题目描述
定义计数器类,包含保护数据成员value,公有函数increment计数加1。
定义循环计算器继承计数器类,增加私有数据成员:最小值minValue,maxValue,
重写公有函数increment,使得value在minValue~maxValue区间内循环+1。
定义时钟类,数据成员是私有循环计数器对象小时hour、分钟minute、秒second,公有函数time(int s)计算当前时间经过s秒之后的时间,即hour,minute,second的新value值。
定义时钟类对象,输入当前时间和经过的秒数,调用time函数计算新时间。
根据题目要求,增加必要的构造函数、析构函数和其他所需函数。
因为clock和time是系统内置函数,为了避免重名,请不要使用clock或者time作为类名或者函数名
输入
第一行测试次数n
2行一组,第一行为当前时间(小时 分钟 秒),第二行为经过的秒数。
输出
输出n行
每行对应每组当前时间和经过秒数后计算得到的新时间(小时:分钟:秒)。
#include<iostream>
#include<cmath>
using namespace std;
class clo
{
protected:
int h, m, s;
public:
clo(int hh,int mm,int ss) :h(hh),m(mm),s(ss)
{
}
};
class ti :public clo
{
private:
int a;
public:
ti(int hh, int mm, int ss,int aa) :clo(hh,mm,ss), a(aa)
{
s += a;
while ( s >= 60)
{
s-= 60;
m++;
}
while (m >= 60)
{
m -= 60;
h++;
}
while (h >= 24)
{
h -= 24;
}
cout << h << ":" << m << ":" << s << "\n";
}
};
int main()
{
int n;
int h, m, s, a;
cin >> n;
while (n--)
{
cin >> h >> m >> s >> a;
ti(h, m, s, a);
}
}