A 钟表类
题目描述
声明一个表示时间的类,可以精确表示 年,月,日,小时,分,秒。
输入
输入六个正整数,中间以空格隔开,分别表示年月日,小时,分,秒。
输出
第一行为年月日,中间以空格隔开,第二行为时分秒,中间以冒号隔开。
样例输入
1993 12 2 22 15 23
样例输出
1993 12 2 22:15:23
代码:
#include<iostream>
using namespace std;
class Time
{
public:
Time()
{
year=0;
mouth=0;
day=0;
hour=0;
minute=0;
second=0;
}
void setBtime(int newy,int newmo,int newd);
void setStime(int newh,int newmi,int news);
void showBtime();
void showStime();
private:
int year,mouth,day,hour,minute,second;
};
void Time::setBtime(int newy,int newmo,int newd)
{
year=newy;
mouth=newmo;
day=newd;
}
void Time::setStime(int newh,int newmi,int news)
{
hour=newh;
minute=newmi;
second=news;
}
inline void Time::showBtime()
{
cout<<year<<" "<<mouth<<" "<<day<<endl;
}
inline void Time::showStime()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
int main()
{
Time myBtime,myStime;
int y,mo,d,h,mi,se;
cin>>y>>mo>>d>>h>>mi>>se;
myBtime.setBtime(y,mo,d);
myStime.setStime(h,mi,se);
myBtime.showBtime();
myStime.showStime();
return 0;
}

浙公网安备 33010602011771号