#include#include using namespace std; class Time { public: //Time(int=0,int=0,int=0); void setTime(int h=0,int m=0,int s=0); void is_Righttime(); void show_time( ); //根據is_24和from0,輸出適合形式-20:23:5/8:23:5 pm/08:23:05 pm void style_time(); void add_seconds(int); //增加n秒鐘 void add_minutes(int); //增加n分鐘 void add_hours(int); //增加n小時 static void change24(); //改變靜態成員is_24,在12和24時制之間轉換 static void changefrom0(); //改變靜態成員from0,切換是否前導0 private: static bool is_24; //為true時,24小時制,如20:23:5;為flase,12小時制,顯示為8:23:5 pm static bool from0; //為true時,前導0,8:23:5顯示為08:23:05 int hour; int minute; int second; }; bool Time::is_24=false; bool Time::from0=false; void Time::setTime(int h,int m,int s) { hour=h; minute=m; second=s; } void Time::change24() { is_24=true; } void Time::changefrom0() { from0=true; } void Time::style_time() { int style; cout<<"請選擇輸出格式:"< >style; switch(style) { case 1: break; case 2: change24(); break; case 3: changefrom0(); break; case 4: change24(); changefrom0(); break; default: cout<<"輸入有誤,請重新輸入:"< >style; } } void Time::add_seconds(int s) { minute+=s/60; while(minute>=60) minute-=60; hour+=1; hour+=s/3600; while(hour>=24) hour-=24; second+=s%60; if(second>59) { minute=minute+1; second-=60; } } void Time::add_minutes(int m) { hour+=m/60; while(hour>=24) hour-=24; minute+=m%60; while(minute>=60) minute-=60; } void Time::add_hours(int h) { hour+=h%24; while(hour>=24) hour-=24; } void Time::show_time() { bool time; if(!is_24&&!from0) { if(hour>12) { hour-=12; cout< 12) { time=false; hour-=12; if(hour<10) cout<<"0"< >chose; switch(chose) { case 0: exit(0); case 1: cout<<"請輸入增加的秒數:"< >sec; T.add_seconds(sec); T.style_time(); T.show_time(); break; case 2: cout<<"請輸入增加的分數:"< >min; T.add_minutes(min); T.style_time(); T.show_time(); break; case 3: cout<<"請輸入增加的時數:"< >hour; T.add_hours(hour); T.style_time(); T.show_time(); break; default: cout<<"輸入有誤,請重新輸入:"< >chose; } } return 0; } void Time::is_Righttime() { int hour,minute,second; char a,b; while(1) { cin>>hour>>a>>minute>>b>>second; if(a!=':'||b!=':') cout<<"格式錯誤,請重新輸入:"< 24||minute<0||minute>60||second<0||second>60) cout<<"時間有誤,請重新輸入:"<