第十二周專案 Time類中的運算子過載

2021-07-11 19:59:34 字數 1722 閱讀 4081

/*

*檔名稱:main.cpp

*作 者:李德坤

*完成日期:2023年5月15日

*版本號:v1.0

* *問題描述:time類中的運算子過載

*輸入描述:時間

*輸出描述:無

*/#include using namespace std;

class ctime

;//建構函式

ctime::ctime(int h,int m,int s)

// 設定時間

void ctime::settime(int h,int m,int s)

// 過載輸入運算子》

istream &operator>>(istream &in,ctime &t)

return cin;

}// 過載輸出運算子<<

ostream &operator<

bool ctime::operator < (ctime &t)// 判斷時間t1t.hour) return false;

if (minutet.minute) return false;

if (secondt) return false;

return true;

}bool ctime::operator != (ctime &t) // 判斷時間t1!=t2

bool ctime::operator >= (ctime &t)// 判斷時間t1>=t2

//二目運算子的過載

// 計算時間之和, 返回c所規定的時、分、秒後的時間,例t1(8,20,25),t2(11,20,50),t1+t2為:41:15

ctime ctime::operator + (ctime &t)

if (m>59)

while (h>23) h-=24;

ctime t0(h,m,s);

return t0;

}//返回s秒後的時間

ctime ctime::operator+(int s)

// 計算時間之差

ctime ctime::operator - (ctime &t)

if (m<0)

while (h<0) h+=24;

ctime t0(h,m,s);

return t0;

}//返回s秒前的時間

ctime ctime::operator-(int s)

//一目運算子的過載

ctime ctime::operator++(int)//後置++,下一秒

ctime &ctime::operator++()//前置++,下一秒

ctime ctime::operator--(int)//後置--,前一秒

ctime &ctime::operator--()//前置--,前一秒

//賦值運算子的過載

ctime &ctime::operator+=(ctime &c)

ctime &ctime::operator-=(ctime &c)

ctime &ctime::operator+=(int s)//返回s秒後的時間

ctime &ctime::operator-=(int s)//返回s秒前的時間

第十二周上機實踐專案2 Time類中的運算子過載

完成日期 2016年6月3日 問題描述 實現time類中的運算子過載。include using namespace std class ctime 建構函式 ctime ctime int h,int m,int s 設定時間 void ctime settime int h,int m,int ...

第十二周專案二Time類中的運算子過載

all right reserved.檔名稱 main。cpp 作 者 閆舒 完成日期 2016年6月21日 版 本 號 vc 6.0 問題描述 實現time類中的運算子過載。輸入描述 程式輸出 include using namespace std class ctime 建構函式 ctime c...

第十二周專案2 Time類中的運算子過載

檔名稱 test.cpp 完成日期 2016年5月19 問題描述 實現time類中的運算子過載。include using namespace std class ctime 建構函式 ctime ctime int h,int m,int s 設定時間 void ctime settime int...