-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path154.cpp
More file actions
51 lines (49 loc) · 943 Bytes
/
154.cpp
File metadata and controls
51 lines (49 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;
class Clock{
public:
Clock(int h,int m,int s){
hour =(h>23? 0:h);
minute = (m>59?0:m);
second = (s>59?0:m);
}
virtual void run(){
second = second+1;
if (second>59)
{
second =0;
minute+=1;
}
if (minute>59)
{
minute =0;
hour+=1;
}
if (hour>23)
{
hour =0;
}
}
virtual void showTime(){
cout<<"Now:"<<hour<<":"<<minute<<":"<<second<<endl;
}
int getHour(){return hour;}
int getMinute(){return minute;}
int getSecond(){return second;}
Clock * createNewClock(int h,int m,int s);
private:
int hour;
int minute;
int second;
};
#include "Clock.h"
class NewClock:public Clock{
public:
NewClock(int h,int m,int s):Clock(h,m,s){};
void showTime()override{
cout<<"Now:"<<(getHour()%12)<<":"<<getMinute()<<":"<<getSecond()<<(getHour()/12?"PM":"AM")<<endl;
}
};
Clock* Clock::createNewClock(int h,int m,int s){
return new NewClock(h,m,s);
}