/*
*檔名稱:main.cpp
*作 者:姜 甜 甜
*完成日期:2023年4月28日
*版 本 號:v1.0
* *問題描述:實現time類中的運算子過載。
*/
#includeusing namespace std;
class ctime
;ctime::ctime(int h,int m,int s)
void ctime::settime(int h,int m,int s)
bool ctime::operator>(ctime &t)
bool ctime::operator<(ctime &t)
bool ctime::operator==(ctime &t)
bool ctime::operator != (ctime &t)
ctime ctime::operator+(ctime &t)
if (m>59)
while (h>23) h-=24;
ctime t0(h,m,s);
return t0;
}ctime ctime::operator-(ctime &t) //注意減法的輸出
if (m<0)
if (h<0) h+=24;
ctime t0(h,m,s);
return t0;
}ctime ctime::operator+(int s)//返回s秒後的時間
ctime ctime::operator-(int s)//返回s秒前的時間
ctime ctime::operator+=(ctime &c)
ctime ctime::operator-=(ctime &c)
ctime ctime::operator+=(int s)//返回s秒後的時間
ctime ctime::operator-=(int s)//返回s秒前的時間
void ctime::display()
if(minute>59)
if(hour>24)
hour=hour/24;
coutt2"<=t2) cout<<"t1≥t2"
t=t1+t2;
t=t1-t2;
t=t1+2000;
t=t1-5000;
t1+=t2;
t1-=t2;
t1+=2000;
t1-=5000;
return 0;
}
注意減法的輸出。
第8周專案2Time類中的運算子過載
all right reserved,檔名 test.cpp 完成日期 2015年5月7日 版本號 v1.0 問題描述 輸入描述 程式輸出 include using namespace std class ctime 建構函式 ctime ctime int h,int m,int s 設定時間 ...
第12周專案2 Time類中的運算子過載
檔名 zhang.cpp 完成日期 2016年5月25日 版本號 v1.0 問題描述 實現time類中的運算子過載。includeusing namespace std class ctime ctime ctime int h,int m,int s hour h minute m second ...
第12周專案2 Time類中的運算子過載
檔名稱 time類中的運算子過載 作 者 岳成豔2016年5月25號 版 本 號 vc 6.0 問題描述 實現time類中的運算子過載。程式輸入 略 程式輸出 略 include using namespace std class ctime ctime ctime int h,int m,int ...