6-7 时间的推算*
分数 20
全屏浏览
切换布局
作者 李祥
单位 湖北经济学院
请设计时间类 TIME,实现时间的输入、输出和推算。
#include <iostream> #include <iomanip> using namespace std; /* 你提交的代码将被嵌在这里 */ int main() { TIME a, b; a.Input(); b = a.Next(); a.Output(); cout << ' '; b.Output(); cout << endl; return 0; }
输入样例
17:32:59
输出样例
17:33:0 17:33:0
要求:
- 设计构造函数,达到以下效果。
TIME a; // 初始化为 0:0:0
TIME a(29, 18, 27); // 初始化为 29:18:27
- 设计输入和输出函数,达到以下效果。
TIME a; a.Input(); // 输入: 28:36:47 a.Output(); // 输出: 28:36:47
- 设计推算函数,达到以下效果。
TIME a(16, 24, 57), b; b = a.Next(); // a 和 b 都变为 16:24:58
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
class TIME
{
int h,m,s;
public:
TIME(int h1=0,int m1=0,int s1=0)
{
h=h1;
m=m1;
s=s1;
}
void Input()
{
char a;
cin>>h>>a>>m>>a>>s;
//cout<<h<<":"<<m<<":"<<s<<endl;
}
void Output()const
{
cout<<h<<":"<<m<<":"<<s;
}
TIME Next()
{
s++;
if(s==60){m++;s=0;}
if(m==60){h++;m=0;}
if(h==24)h=0;
return *this;
}
};