第9周專案2Time類中運算子過載(續)

2021-07-02 12:09:20 字數 1006 閱讀 5558

問題描述:

定義對時間物件的自增自減,一目運算子和<<>>運算子過載,實現時間的輸入輸出

#include

*this=*this+1;

return *this;

}ctime ctime::operator++(int )

ctime ctime::operator--()

ctime ctime::operator--(int )

//二目運算子的過載的定義

ctime ctime::operator+(ctime &c)

if(m>=60)

while(h>=24)

ctime t(h,m,s);

return t;

}ctime ctime::operator+(int s)

ctime ctime::operator-(ctime &c)

if(m<0)

while(h<0)

ctime t(h,m,s);

return t;

}ctime ctime::operator-(int s)

//賦值運算子的過載的定義

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

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

ctime ctime:: operator+=(int c)

ctime ctime::operator-=( int c)

//比較運算子的過載的定義

bool ctime::operator>(ctime &c)

bool ctime::operator>=(ctime &c)

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

{if(*this>c||*this>c1;

cout<<"c2為 ";

cin>>c2;

cout<<"比較c1,c2這兩個時間的大小:"c2"<=c2)cout<<"c1>=c2"cout<<"c= "<

第9周專案2 Time類中的運算子過載(續)

檔名稱 main.cpp 作 者 姜 甜 甜 完成日期 2015年5月8日 版 本 號 v1.0 問題描述 實現time類中的運算子過載。includeusing namespace std class ctime istream operator istream in,ctime t return...

第9周專案2 Time類中的運算子過載(續)

問題描述 在time類中的運算子過載基礎上 1 定義對時間物件的自增和自減一目運算子 2 定義time類中的 和 運算子過載,實現時間的輸入輸出,改造原程式中對運算結果顯示方式,使程式讀起來更自然。include using namespace std class ctime istream ope...

第9周專案2 Time類中的運算子過載續(1)

all right reserved,檔名 test.cpp 完成日期 2015年5月17日 版本號 v1.0 問題描述 輸入描述 程式輸出 include using namespace std class ctime 建構函式 ctime ctime int h,int m,int s 設定時間...