-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path24_greaterThanOpOverloadTime.cpp
64 lines (56 loc) · 1.07 KB
/
24_greaterThanOpOverloadTime.cpp
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
#include<iostream>
using namespace std;
class Time
{
private:
int HR, MIN, SEC; //member variables
public:
void setTime();
void showTime();
void normalize();
bool operator>(Time t)
{
if(HR*60*60+MIN*60+SEC > t.HR*60*60+t.MIN*60+t.SEC)
return 1;
return 0;
}
};
void Time:: setTime()
{
cout << "Enter the time (h m s) : ";
cin >> HR >> MIN >> SEC;
normalize();
}
void Time:: showTime()
{
cout << "Time : " << HR << ":" << MIN << ":" << SEC << endl;
}
void Time:: normalize()
{
if(SEC>=60)
{
SEC = SEC-60;
MIN = MIN + 1;
}
if(MIN>=60)
{
MIN = MIN - 60;
HR = HR + 1;
}
while(1)
if(HR>=24)
HR = HR - 24;
else
break;
}
int main()
{
Time t1,t2;
t1.setTime();
t2.setTime();
t1.showTime();
t2.showTime();
int x = t1>t2;
cout << x;
return 0;
}