2614: A代码完善--系统日期
时间限制: 1 Sec 内存限制: 128 MB
提交: 216 解决: 113
题目描述
注:本题只需要提交填写部分的代码,请按照C++方式提交。
已知某操作系统的默认日期时间格式为 MMDDhhmmYYYY.ss ,其中YYYY表示年,MM表示月,DD表示日,hh表示小时,mm表示分种,ss表示秒。
按要求设计日期时间类DateTime,显示指定格式的日期。
#include <iostream>
#include <stdio.h>
#include <iomanip>
using namespace std;
class Date
{
public:
Date(int year,int month,int day):year(year),month(month),day(day) {}
Date(const Date &d)
{
this->year=d.year;
this->month=d.month;
this->day=d.day;
}
protected:
int year;
int month;
int day;
};
class Time
{
public:
Time(int hour,int minute,int seconds):hour(hour),minute(minute),seconds(seconds) {}
Time(const Time &t)
{
this->hour=t.hour;
this->minute=t.minute;
this->seconds=t.seconds;
}
protected:
int hour;
int minute;
int seconds;
};
/*************************
在此处补充和修改你的代码
class DateTime :protected Date,protected Time
{
public:
DateTime(Date &d, Time &t )
void show()
};
**************************/
int main()
{
int year,month,day;
cin>>year>>month>>day;
Date d1(year,month,day);
int hour,minute,seconds;
cin>>hour>>minute>>seconds;
Time t1(hour,minute,seconds);
DateTime dt(d1,t1);
dt.show();
return 0;
}
输入
年 月 日 小时 分钟 秒
输出
按格式MMDDhhmmYYYY.ss显示日期
样例输入
2014 7 10 10 30 15
样例输出
071010302014.15
提示
前导0的输出,printf("%02d",5) ; 显示为 05。
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <iostream>
#include <stdio.h>
#include <iomanip>
using namespace std;
class Date
{
public:
Date(int year,int month,int day):year(year),month(month),day(day) {}
Date(const Date &d)
{
this->year=d.year;
this->month=d.month;
this->day=d.day;
}
protected:
int year;
int month;
int day;
};
class Time
{
public:
Time(int hour,int minute,int seconds):hour(hour),minute(minute),seconds(seconds) {}
Time(const Time &t)
{
this->hour=t.hour;
this->minute=t.minute;
this->seconds=t.seconds;
}
protected:
int hour;
int minute;
int seconds;
};
class DateTime :protected Date,protected Time
{
public:
DateTime(Date &d, Time &t ): Date(d),Time (t) {}
void show()
{
printf("%02d%02d%02d%02d%d.%02d\n",month,day,hour,minute,year,seconds);
}
};
int main()
{
int year,month,day;
cin>>year>>month>>day;
Date d1(year,month,day);
int hour,minute,seconds;
cin>>hour>>minute>>seconds;
Time t1(hour,minute,seconds);
DateTime dt(d1,t1);
dt.show();
return 0;
}
#include <stdio.h>
#include <iomanip>
using namespace std;
class Date
{
public:
Date(int year,int month,int day):year(year),month(month),day(day) {}
Date(const Date &d)
{
this->year=d.year;
this->month=d.month;
this->day=d.day;
}
protected:
int year;
int month;
int day;
};
class Time
{
public:
Time(int hour,int minute,int seconds):hour(hour),minute(minute),seconds(seconds) {}
Time(const Time &t)
{
this->hour=t.hour;
this->minute=t.minute;
this->seconds=t.seconds;
}
protected:
int hour;
int minute;
int seconds;
};
class DateTime :protected Date,protected Time
{
public:
DateTime(Date &d, Time &t ): Date(d),Time (t) {}
void show()
{
printf("%02d%02d%02d%02d%d.%02d\n",month,day,hour,minute,year,seconds);
}
};
int main()
{
int year,month,day;
cin>>year>>month>>day;
Date d1(year,month,day);
int hour,minute,seconds;
cin>>hour>>minute>>seconds;
Time t1(hour,minute,seconds);
DateTime dt(d1,t1);
dt.show();
return 0;
}