CTime operator++();//前置++,下一秒,前置与后置返回值不一样
CTime operator--( int);//后置--,前一秒
CTime operator--();//前置--,前一秒
//赋值运算符的重载
CTime operator+=(CTime &c);
CTime operator-=(CTime &c);
CTime operator+=(int s);
CTime operator-=(int s);
};
//下面实现所有的运算符重载代码。
void CTime::display()
{
cout<
bool CTime::operator>(CTime &t)
{
if(hour==t.hour)
{
if(minute==t.minute)
{
if(second>t.second)
return true;
else
return false;
}
if(minute>t.minute)
return true;
else
return false;
}
if(hour>t.hour)
return true;
else
return false;
}
bool CTime::operator<(CTime &t)
{
if(hour==t.hour)
{
if(minute==t.minute)
{
if(second
else
return false;
}
if(minute
else
return false;
}
if(hour
else
return false;
}
bool CTime::operator>=(CTime &t)
{
if(hour==t.hour)
{
if(minute==t.minute)
{
if(second>=t.second)
return true;
else
return false;
}
if(minute>t.minute)
return true;
else
return false;
}
if(hour>t.hour)
return true;
else
return false;
}
bool CTime::operator<=(CTime &t)
{
if(hour==t.hour)
{
if(minute==t.minute)
{
if(second<=t.second)
return true;
else
return false;
}
if(minute
else
return false;
}
if(hour
else
return false;
}
bool CTime::operator==(CTime &t)
{
if(hour==t.hour&&minute==t.minute&&second==t.second)
return true;
else
return false;
}
bool CTime::operator!=(CTime &t)
{
if(hour==t.hour&&minute==t.minute&&second==t.second)
return false;
else
return true;
}
CTime CTime::operator+(CTime &c)
{
CTime t;
t.hour=hour+c.hour;
t.minute=minute+c.minute;
t.second=second+c.second;
if(t.second>=60)
{
t.second=t.second-60;
t.minute=t.minute+1;
}
if(t.minute>=60)
{
t.minute=t.minute-60;
t.hour=t.hour+1;
}
if(t.hour>=24)
{
t.hour=t.hour-24;
}
return t;
}
CTime CTime::operator-(CTime &c)
{
int h,m,s;
s=second-c.second;
m=minute-c.minute;
h=hour-c.hour;
if (s<0)
{
s+=60;
m--;
}
if (m<0)
{
m+=60;
h--;
}
if (h<0) h+=24;
CTime t0(h,m,s);
return t0;
}
CTime CTime::operator+(int s)
{
int ss=s%60;
int mm=(s/60)%60;
int hh=s/3600;
CTime t0(hh,mm,ss);
return *this+t0;
}
CTime CTime::operator-(int s)
{
int ss=s%60;
int mm=(s/60)%60;
int hh=s/3600;
CTime t0(hh,mm,ss);
return *this-t0;
}
CTime CTime::operator++(int)//后置++,下一秒
{
CTime t=*this;
*this=*this+1;
return t;
}
CTime CTime::operator++()//前置++,下一秒
{
*this=*this+1;
return *this;
}
CTime CTime::operator--(int)//后置--,前一秒
{
CTime t=*this;
*this=*this-1;
return t; }
CTime CTime::operator--()//前置--,前一秒
{
*this=*this-1;
return *this;
}
CTime CTime::operator+=(CTime &c)
{
*this=*this+c;
return *this;
}
CTime CTime::operator-=(CTime &c)
{
*this=*this-c;
return *this;
}
CTime CTime::operator+=(int s)//返回s秒后的时间