/* (程式頭部注釋開始)
02.* 程式的版權和版本宣告部分
05.* 檔名稱:
06.
07.* 作 者: 王明星
08.* 完成日期: 2012 年4 月 8 日
09.* 版 本 號:
10.* 對任務及求解方法的描述部分
11.* 輸入描述:
12.* 問題描述:
13.* 程式輸出:
14.* 程式頭部的注釋結束
15.*/
#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);
//二目運算子的過載
ctime operator+(ctime &c);//返回c所規定的時、分、秒後的時間,例t1(8,20,25),t2(11,20,50),t1+t2為:41:15
ctime operator-(ctime &c);//對照+理解
ctime operator+(int s);//返回s秒後的時間
ctime operator-(int s);//返回s秒前的時間
//一目運算子的過載
ctime operator++(int);//後置++,下一秒
ctime operator++();//前置++,下一秒
ctime operator--(int);//後置--,前一秒
ctime operator--();//前置--,前一秒
//賦值運算子的過載
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)//大於比較符(把時間都化成秒進行比較要容易得多,下同)
else
return false;
} bool ctime::operator < (ctime &t)//小於比較符
else
return false;
} bool ctime::operator <= (ctime &t)//小於等於比較符
else
return false;
} bool ctime::operator == (ctime &t)//等於比較符
else
return false;
} bool ctime::operator != (ctime &t)//不等於
else
return false;
} //二目運算子的過載
ctime ctime::operator+(ctime &t)//返回c所規定的時、分、秒後的時間,例t1(8,20,25),t2(11,20,50),t1+t2為:41:15
ctime ctime::operator-(ctime &t)//對照+理解
t1.hour=time/3600;
time =time%3600;
t1.minute =time/60;
time = time%60;
t1.second =time;
return t1;
} ctime ctime::operator+(int s)//返回s秒後的時間
ctime ctime::operator-(int s)//返回s秒前的時間
//一目運算子的過載
ctime ctime::operator++(int)//後置++,下一秒
} }
return temp;//返回的物件為改之前的,但實際物件已經改變了
} ctime ctime::operator++()//前置++,下一秒
} return (*this);
} ctime ctime::operator--(int)//後置--,前一秒
} return temp;
} ctime ctime::operator--()//前置--,前一秒
} return (*this);
} //賦值運算子的過載
ctime ctime::operator+=(ctime &t)
time = time%3600;
minute = time/60;
time = time%60;
second = time;
return (*this);
} ctime ctime::operator-=(ctime &t)
hour = time/3600;
if(hour>=24)
time = time%3600;
minute = time/60;
time = time%60;
second = time;
return (*this);
} ctime ctime::operator+=(int s)//返回s秒後的時間
if(minute>=60)
if(hour>=24)
return (*this);
} ctime ctime::operator-=(int s)//返回s秒前的時間
else
hour = time/3600;
time = time%3600;
minute = time/60;
time = time%60;
second = time;
return (*this);
}
void main()
第八周任務2
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 oper...
第八周 任務一
實驗內容 實現複數類中的運算子過載定義乙個複數類過載運算子 使之能用於複數的加減乘除。程式的版權和版本宣告部分 檔名稱 實現複數類中的運算子過載 作 者 薛廣晨 完成日期 2012 年 4 月 7 日 版 本號 x1.0 對任務及求解方法的描述部分 輸入描述 程式頭部的注釋結束 此處也刪除了斜槓 任...
第八周 任務四
實驗內容 實現分數的運算子過載 程式的版權和版本宣告部分 檔名稱 實現分數的運算子過載 作 者 薛廣晨 完成日期 2012 年 4 月 7 日 版 本號 x1.0 任務4 在任務3的基礎上拓展。分數類中的物件可以和整型數進行四則運算,且運算符合交換律。例如 cfraction a 1,3 b int...