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

2021-07-13 01:59:24 字數 1633 閱讀 1717

/*

*完成日期:2023年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 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秒前的時間

第十二周上機實踐專案(1)

檔名稱 text11.cpp 問題描述 分別定義teacher 教師 類和cadre 幹部 類,採用多重 繼承方式由這兩個類派生出新類teacher cadre 教師兼幹部 1 在兩個基類中都包含姓名 年齡 性別 位址 等資料成員。2 在teacher類中還包含資料成員title 職稱 在cadre...

第十二周上機任務2

檔案注釋頭部開始 程式的版權和版本宣告部分 檔名稱 字串中單詞個數的統計 作 者 劉文英 完成日期 2012年5月7號 版本號 v.2 對任務及求解方法的描述部分 輸入描術 問題描述 教材p394習題9 分別定義teacher 教師 類和cadre 幹部 類,採用多重繼承方式由這兩個類派生出新類te...

第十二周專案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...