第7周專案2

2021-07-02 02:17:42 字數 2157 閱讀 6412

#includeusing namespace std;

class ctime

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為19: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秒前的時間

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

void ctime::display()

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

return false;

if (minutet.minute)

return false;

if (secondt);

}bool ctime::operator>=(ctime &t)

//可以直接使用已經過載了的加減運算實現

//這種賦值, 例如 t1+=20,直接改變當前物件的值,所以在運算完成後,將*this作為返回值

ctime ctime::operator+(ctime &t)

if(m>59)

if(h>23)

h-=24;

ctime t1(h,m,s);

return t1;

}ctime ctime::operator+(int s)

if(minute>59)

if(hour>23)

hour-=24;

ctime t1(hour,minute,ss);

return t1;

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

if(m<0)

if(h<0)

h+=24;

ctime t1(h,m,s);

return t1;

}ctime ctime::operator-(int s)

if(minute<0)

if(hour<0)

hour+=24;

ctime t1(hour,minute,ss);

return t1;

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

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

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

第7周專案2電阻併聯

問題及 檔名稱 rrr.cpp 作 者 單昕昕 完成日期 2014年10月9日 版 本 號 v1.0 問題描述 輸入兩個電阻r1和r2的阻值,計算並輸出它們併聯後的阻值r 輸入描述 兩個整數,代表兩個電阻值 程式輸出 乙個整數,代表併聯電阻的阻值 include using namespace st...

第13周專案2

檔名稱 完成日期 2014 年 5 月 20 日 版本號 v1.0 對任務及求解方法的描述部分 輸入描述 問題描述 程式輸出 圓的比較 問題分析 演算法設計 include include using namespace std class point point double get x doub...

第8周 專案2

問題及 檔名稱 zwj.cpp 作 者 王藝霖 完成日期 2016年4月18日 版 本 號 v1.0 問題描述 編寫基於物件的程式,求5個長方柱的體積和表面積。長方柱類bulk的資料成員包括長 length 寬 width 高 heigth 等。對照已經給出的 要做的工作及要求有 需要你定義長方柱類...