电子时钟中的运算符重载
来源:互联网 发布:js初始化加载 编辑:程序博客网 时间:2024/06/06 08:54
4-2 电子时钟中的运算符重载
Problem Description
Input
输入6个整数,之间用一个空格间隔;分别表示开始时间的时、分、秒和结束时间的时、分、秒的值
Output
从开始时间到结束时间之间所有时间对象的值;每个值占一行,格式为hh:mm:ss
Example Input
01 01 01 01 01 10
Example Output
01:01:0101:01:0201:01:0301:01:0401:01:0501:01:0601:01:0701:01:0801:01:0901:01:10
Hint
Author
黄晶晶
#include<bits/stdc++.h>
using namespace std;
class Time
{
private:
int hour, minute, second;
public:
Time()
{
hour = 0; minute = 0; second = 0;
}
Time(int x = 0, int y = 0, int z = 0)
{
hour = x; minute = y; second = z;
}
Time operator++();
void display();
int cmp(Time &t);
};
Time Time::operator++()
{
if(++second >= 60)
{
second -= 60;
if(++minute >= 60)
{
minute -= 60;
++hour;
}
}
}
void Time::display()
{
if(hour < 10)
cout<<0<<hour<<":";
else
cout<<hour<<":";
if(minute < 10)
cout<<0<<minute<<":";
else
cout<<minute<<":";
if(second < 10)
cout<<0<<second;
else
cout<<second;
cout<<endl;
}
int Time::cmp(Time &t)
{
if(hour > t.hour)
return 0;
else if(hour == t.hour && minute > t.minute)
return 0;
else if(hour == t.hour && minute == t.minute && second > t.second)
return 0;
else return 1;
}
int main()
{
int h1, m1, s1, h2, m2, s2;
cin>>h1>>m1>>s1;
cin>>h2>>m2>>s2;
Time t1(h1,m1,s1);
Time t2(h2,m2,s2);
if(!t1.cmp(t2))
cout<<"The begin time is not earlier than the end time!"<<endl;
else
{
while(t1.cmp(t2))
{
t1.display();
++t1;
}
}
return 0;
}
- 电子时钟中的运算符重载
- 4-2电子时钟中的运算符重载
- [2711]4-2 电子时钟中的运算符重载
- SDUTOJ 2711 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- SDUT OJ4-2 电子时钟中的运算符重载
- sdut oj4-2 电子时钟中的运算符重载
- SDUT-2711 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- 4-2 电子时钟中的运算符重载
- maven的入门
- Python中的join()函数的用法(字符串和os.path)
- git代码提交
- Kubernetes网络原理
- HDU 2520.我是菜鸟,我怕谁
- 电子时钟中的运算符重载
- 两台Linux 服务器 SSH免密码登录
- picasso教程
- 由于权限不足而无法读取配置文件出现的HTTP 500.19解决办法
- 如何给所有连接设备更新apk版本
- 用户权限管理模块的数据库设计
- 大话设计模式-备忘录模式学习总结
- json数据处理
- 面向对象程序设计上机练习十(运算符重载)