有点想不出来
// 定义一个时间类,包含hour,minute,second 数据成员,定义合适的构造函数对其进行初始化,并定义输出函数将其输出,// 并对单目运算符++(前自增、后自增)进行重载,能对对象执行加一操作,完成秒数上加一的功能,如time t1(13,25,36),
// 执行t1++ ()后,其数据成员为13,25,37
#include<iostream.h>
class time
{
private:
int hour;
int minute;
int second;
public:
time();
time(int h,int m,int s);
time operator++();
time operator++(int);
friend ostream &operator<<(ostream &out,time x);
};
time::time()
{
hour=12;
minute=0;
second=0;
}
time::time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
time time::operator++()
{
this->second++;
if(this->second==60)
{
this->second=0;
this->minute++;
}
return *this;
}
time time::operator++(int)
{
time temp=*this;
this->second++;
if(this->second==60)
{
this->second=0;
this->minute++;
}
return temp;
}
ostream &operator<<(ostream &out,time x)
{
if(x.minute>=10)
{
if(x.second>=10)
out<<x.hour<<":"<<x.minute<<":"<<x.second;
else
out<<x.hour<<":"<<x.minute<<":0<<x.second";
}
else
{
if(x.second>=10)
out<<x.hour<<":"<<"0"<<x.minute<<":"<<x.second;
else
out<<x.hour<<":"<<"0"<<x.minute<<":0<<x.second";
}
return out;
}
void main()
{
time t1(13,25,59),t2;
cout<<t1<<endl;
t2=++t1;
cout<<t2<<endl;
}