有一个TIME的类要求输出分和秒的值

时间:2022-09-07 08:40:14
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class Time
{
public:
Time()
{
minute=;
sec=;
}
Time(int m,int s):minute(m),sec(s){
}
Time operator++();
void display()
{
cout<<minute<<":"<<sec<<endl;
}
private:
int minute;
int sec;
}; Time Time::operator++()
{
if(++sec>=)
{
sec-=;
++minute;
}
return *this;
}
int main(int argc, char** argv) {
Time time1(,);
for(int i=;i<;i++)
{
++time1;
time1.display();
}
return ;
}

相关文章