函式過載實現Time類

2021-06-21 15:35:29 字數 1447 閱讀 3146

/*

*檔名稱:

*完成日期:2023年4月22日

*版本號:v0.1

*對任務及求解方法的描述部分:

*輸入描述:無

*問題描述: 過載運算子實現 time類的過載

*程式輸入:

*程式輸出:

*問題分析:略

*演算法設計:略

*我的程式:

*/#include using namespace std;

class ctime

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

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

void ctime::display()

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

return false;

if (mint.min)

return false;

if (sect)

return false;

return true;

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

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

bool ctime::operator <= (ctime &t)

ctime ctime::operator + (ctime &t)

if (m>59)

if (h>23) h-=24;

ctime t0(h,m,s);

return t0;

}ctime ctime::operator+(int s)

ctime ctime::operator - (ctime &t)

if (m<0)

if (h<0) h+=24;

ctime t0(h,m,s);

return t0;

}ctime ctime::operator-(int s)

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

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

ctime ctime::operator+=(int s)

ctime ctime::operator-=(int s)

int main()

{ ctime t1(8,20,25),t2(11,20,50),t;

cout<

t1.display();

cout<

t2.display();

cout<

if (t1>t2) cout執行結果:

心得體會:

8 2 實現Time類中的運算子過載

作 者 霍雨佳 完成日期 2014 年4月15日 版 本 號 v1.0 問題描述 實現time類中的運算子過載 樣例輸入 樣例輸出 專案要求 實現time類中的運算子過載 include using namespace std class ctime void settime int h,int m...

Time類的運算子過載

main.cpp project created by 徐偉 on 6 8 16.includeusing namespace std class ctime ctime ctime int h,int m,int s void ctime settime int h,int m,int s voi...

Time類中的運算子過載

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 operat...