-
Notifications
You must be signed in to change notification settings - Fork 20
/
old.clock.cc
99 lines (88 loc) · 2.15 KB
/
old.clock.cc
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
#include<string>
using namespace std;
class Time{
public:
Time(){ //consturctor initializes variables and other objects
hours=mins=secs=-1;
} //end of constructor
~Time(){} //destructor destroys/closes resources to reclaim memory
void setTime(int sethours, int setmins, int setsecs){
if(sethours>23 || sethours<0)
{
cout<<"Invalid hours"<<endl;
}else{
hours = sethours;}
if(setmins>59 || setmins<0)
{
cout<<"Invalid minutes"<<endl;}
else{
mins = setmins;}
if(setsecs>59 || setsecs<0)
{
cout<<"Invalid seconds"<<endl;}
else{
secs=setsecs;}
}
<<<<<<< HEAD:old.clock.cc
void displayTime(void){
cout<<hours<<":"<<mins<<":"<<secs<<ampm<<" . . . . . .In 12H clock system.\n";
}
/*This function displays the values of the time in 24H clock system without the AM/PM */
void displayTime_12Hours(void){
cout<<hours<<":"<<mins<<":"<<secs<<" . . . . . .In 24H clock system.\n";
}
=======
virtual void displayTime(void){}
>>>>>>> 928598d90f8af867c2d49d911cfcd860e08ad9c2:clock.cc
protected: int hours;
int mins;
int secs;
char ampm[3];
}; //end class Time
class Clock12: public Time{
public:
void setAMPM(void){
if(hours>=12){
if(hours>12)
hours=hours-12;
std::string str (" PM");
str.copy(ampm, 3, 0);
}else{
std::string str (" AM");
str.copy(ampm, 3, 0);
}
}
void displayTime(void){
if(hours == -1 ||mins==-1||secs==-1){
cout<<"Invalid time"<<endl;}
else{
cout<<hours<<":"<<mins<<":"<<secs<<ampm<<"\n";
}
}
};
class Clock24: public Time{
public:
void displayTime(void){
if(hours == -1 ||mins==-1||secs==-1){
cout<<"Invalid time"<<endl;}
else{
cout<<hours<<":"<<mins<<":"<<secs<<ampm<<"\n";}
}
};
int main(){
<<<<<<< HEAD:old.clock.cc
Clock clk;
clk.setTime(22,2,40);
clk.displayTime_12Hours(); /*Put before the setAMPM() call for the () not to interfere with the initialised values in setTime()*/
=======
Clock12 clk;
clk.setTime(16,50,29);
>>>>>>> 928598d90f8af867c2d49d911cfcd860e08ad9c2:clock.cc
clk.setAMPM();
clk.displayTime();
Clock24 clkt;
clkt.setTime(17,47,03);
clkt.displayTime();
return 0;
}