|
#include<iostream>
using namespace std;
class Time
{
int hour;
int minute;
int second;
public:
void settime(int h,int m,int s); //设置时间
void showtime(){cout<<hour<<":"<<minute<<":"<<second<<endl;} //输出时间
void run(); //每调用一次该方法,时间增加一秒
};
void Time::settime(int h,int m,int s)
{
hour=h;minute=m;second=s;
m+=s/60;s%=60;
h+=m/60;h%=24;
m%=60;
}
void Time::run()
{
assert(second>=0&&second<=60);
if(second<59)
{
second+=1;
}
else if(second==59){minute+=1;second=0;}
else {minute+=1;second=1;}
}
int main()
{
cout<<"How many array you want to input: ";int arrNum;
cin>>arrNum;
Time time[arrNum];
for (int i=0;i<arrNum;i++)
{
cout<<"The "<<i+1<<"th array!\n";
int h,m,s;
cin>>h>>m>>s;time[i].settime(h,m,s);
int r;
cin>>r;
for (int j=0;j<r;j++)
{
time[i].run();
}
}
for (int k=0;k<arrNum;k++)
{
time[k].showtime();
}
system("pause");
return 0;
} |
|