forked from Muriukidavid/cplusplus_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.cc
50 lines (44 loc) · 788 Bytes
/
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
#include<iostream>
#include<string>
using namespace std;
class Time{
public:
void setTime(int sethours, int setmins, int setsecs){
hours = sethours;
mins = setmins;
secs=setsecs;
}
void displayTime(void){
cout<<hours<<":"<<mins<<":"<<secs<<ampm<<"\n";
}
void display(void){
cout<<hours<<":"<<mins<<":"<<secs<<"\n";
}
protected: int hours;
int mins;
int secs;
char ampm[3];
};
class Clock: 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);
}
}
};
int main(){
Clock clk;
clk.setTime(13,25,40);
clk.display();
clk.setAMPM();
clk.displayTime();
return 0;
}