forked from Muriukidavid/cplusplus_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.cc
More file actions
44 lines (39 loc) · 695 Bytes
/
Copy pathclock.cc
File metadata and controls
44 lines (39 loc) · 695 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
#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";
}
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.setAMPM();
clk.displayTime();
return 0;
}