4 2 電子時鐘中的運算子過載

2021-07-23 05:42:32 字數 1649 閱讀 1806

time limit: 1000ms

memory limit: 65536kb

submit

statistic

problem description

通過本題目的練習可以運算子過載的方法;

設計乙個時間類time,私有資料成員有hour(時)、minute(分)、second(秒);

公有成員函式有:sethour(int)設定資料成員hour的值,非法的輸入預設為12;setminue(int)設定資料成員minute的值,非法輸入預設為0;setsecond(int)設定資料成員second的值,非法輸入預設為0;settime(int,int,int)設定時、分、秒三個資料成員的值;三個成員函式int gethour(); int getminute(); int getsecond();分別用於獲取時間物件的屬性值。

定義兩個建構函式time(); 和 time(int,int,int);

定義乙個成員函式void displaytime(); 用於顯示時間,注意格式為 hh:mm:ss,位數不夠用0填充;

定義乙個時鐘增加1的成員函式 void tick(); 把second的值加1,並注意是否到60;

定義乙個成員或友元函式 bool operator= =(….); 判斷兩個時間物件的值是否相等;

定義乙個成員或友元函式bool operator>(…..); 判斷第乙個時間物件的值是否大於第二個時間物件的值。

在主函式main()中指定開始時間和結束時間,並呼叫相應成員函式,顯示從開始時間到結束時間之間所有時間物件的值,其格式見示例輸出。

input輸入6

個整數,之間用乙個空格間隔;分別表示開始時間的時、分、秒和結束時間的時、分、秒的值

output

從開始時間到結束時間之間所有時間物件的值;每個值佔一行,格式為

hh:mm:ss

example input

01 01 01 01 01 10

example output

01:01:01

01:01:02

01:01:03

01:01:04

01:01:05

01:01:06

01:01:07

01:01:08

01:01:09

01:01:10

hint輸入

11 10 12 10 12 56 輸出

the begin time is not earlier than the end time!

#include #include using namespace std;

class time

void setminue(int a)

void setsecond(int a)

void settime(int a,int b,int c)

int gethour()

int getminute()

int getsecond()

time(){};

time(int a,int b,int c);

void displaytime()

};int main()

}return 0;

}

4 2電子時鐘中的運算子過載

4 2 電子時鐘中的運算子過載 time limit 1000ms memory limit 65536k 通過本題目的練習可以運算子過載的方法 設計乙個時間類time,私有資料成員有hour 時 minute 分 second 秒 公有成員函式有 sethour int 設定資料成員hour的值,...

4 2電子時鐘中的運算子過載

4 2 電子時鐘中的運算子過載 time limit 1000ms memory limit 65536k 通過本題目的練習能夠運算子過載的方法 設計乙個時間類time,私有資料成員有hour 時 minute 分 second 秒 公有成員函式有 sethour int 設定資料成員hour的值。...

sdut oj4 2 電子時鐘中的運算子過載

4 2 電子時鐘中的運算子過載 time limit 1000ms memory limit 65536kb problem description 通過本題目的練習可以運算子過載的方法 設計乙個時間類time,私有資料成員有hour 時 minute 分 second 秒 公有成員函式有 seth...