-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.cpp
More file actions
70 lines (55 loc) · 1.26 KB
/
Clock.cpp
File metadata and controls
70 lines (55 loc) · 1.26 KB
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
#include "Clock.hpp"
//validator
bool IsValid(int hour, int minute, int second) {
return ((hour >= 0 && hour <= 23) && (minute >= 0 && minute <= 59) && (second >= 0 && second <= 59));
}
//Construcktor
clock MakeClock(int hour, int minute, int second) {
clock jam;
if( IsValid(hour, minute, second)){
jam.HH = hour;
jam.MM = minute;
jam.SS = second;
}
return jam;
}
//Selector
int GetHour(clock c) {
return c.HH;
}
int GetMinute(clock c) {
return c.MM;
}
int GetSecond(clock c) {
return c.SS;
}
//Value Changer
void SetHour(clock * c, int newHH){
(*c).HH = newHH;
}
void SetMinute(clock * c, int newMM){
(*c).MM = newMM;
}
void SetSecond(clock * c, int newSS){
(*c).SS = newSS;
}
//Relational Operation
bool IsEqual(clock c1, clock c2) {
return (c1.HH == c2.HH && c2.MM == c1.MM && c1.SS == c2.SS);
}
//Arithmetic Operation
clock AddClock(clock c1, clock c2) {
int jam, menit, detik;
jam = c1.HH + c2.HH;
menit = c1.MM + c2.MM;
detik = c1.SS + c2.SS;
if( IsValid(jam, menit, detik)){
return MakeClock(jam, menit, detik);
} else {
return MakeClock(0,0,0);
}
}
//Output Process
void PrintClock(clock c) {
cout<<"Jam "<<c.HH<<":"<<c.MM<<":"<<c.SS<<endl;
}