Unit8 problem2 Time運算子過載

2021-06-21 15:36:30 字數 2091 閱讀 7816

/*univercity:煙台大學

*@class計134~4

*@author:薛富磊

*@time:2014-4-18

*@function:

*@args:

*@return:

*/#include using namespace std;

class ctime

; void settime(int h,int m,int s);

void display();

//二目的比較運算子過載

bool operator > (ctime &t);

bool operator < (ctime &t);

bool operator >= (ctime &t);

bool operator <= (ctime &t);

bool operator == (ctime &t);

bool operator != (ctime &t);

//二目的加減運算子的過載

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

ctime operator+(ctime &t);

ctime operator-(ctime &t);//對照+理解

ctime operator+(int s);//返回s秒後的時間

ctime operator-(int s);//返回s秒前的時間

//二目賦值運算子的過載

ctime operator+=(ctime &c);

ctime operator-=(ctime &c);

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

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

};//下面實現所有的運算子過載**。

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

void ctime::display()

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(c.second>=60)

return c;

}ctime ctime::operator-(ctime &t)

else

c.minute=minute-t.minute;

if(second-t.second<0)

else

c.second=second-t.second;

return c;

}ctime ctime::operator+(int s)

ctime ctime::operator-(int s)

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

if(c.second>=60)

return c;

}ctime ctime::operator-=(ctime &t)

else

c.minute=minute-t.minute;

if(second-t.second<0)

else

c.second=second-t.second;

return c;

}ctime ctime::operator+=(int s)

ctime ctime::operator-=(int s)

//自行編制用於測試的main()函式,有些結果不必依賴display()函式,提倡用單步執行檢視結果

int main()

/*一直拖到現在

很多都沒寫

只能等到五一

加油吧!!!*/

Time類中的運算子過載(2) 二目運算子的過載

問題描述及 檔名稱 hellow.cpp 完成日期 2016年5月19日 版本號 v1.0 問題描述 實現time類中的運算子過載。輸入描述 程式輸出 include using namespace std class ctime void set time int h,int m,int s vo...

專案2 Time類中的運算子過載

問題及 檔名稱 main.cpp 作 者 李磊濤 版 本 號 v1.0 問題描述 專案 time類中的運算子過載 輸入描述 無。程式輸出 兩個數的演算法公式及結果。includeusing namespace std class ctime ctime ctime int h,int m,int s...

第8周 任務2 實現Time類中的運算子過載

程式頭部注釋開始 程式的版權和版本宣告部分 檔名稱 實現time類中的運算子過載 並對運算子的過載進行測試 作 者 馬琳 完成日期 2012 年 04 月 11日 版 本 號 v1.0 對任務及求解方法的描述部分 輸入描述 問題描述 程式輸出 程式頭部的注釋結束 include using name...