-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice1.cpp
More file actions
57 lines (52 loc) · 974 Bytes
/
Copy pathpractice1.cpp
File metadata and controls
57 lines (52 loc) · 974 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
45
46
47
48
49
50
51
52
53
54
55
56
57
//overloading of greater than operator
#include <iostream>
using namespace std;
class Time
{
private:
int Hr,Min,Sec;
public:
void setTime(int h,int m,int s)
{
Hr = h;
Min = m;
Sec = s;
}
void showTime()
{
cout<<"\nTime "<<Hr<<":"<<Min<<":"<<Sec<<endl;
}
int operator>(Time t)
{
if(Hr>t.Hr)
return 1;
else if(Hr<t.Hr)
return 0;
else if(Min>t.Min)
return 1;
else if(Min<t.Min)
return 0;
else if(Sec>t.Sec)
return 1;
else if (Sec<t.Sec)
return 0;
}
};
int main()
{
int h,m,s;
system("cls");
cout<<"Enter Time(H:M:S) ";
cin>>h>>m>>s;
Time t1,t2;
t1.setTime(h,m,s);
cout<<"Enter Time(H:M:S) ";
cin>>h>>m>>s;
t2.setTime(h,m,s);
//checking > operator
if(t1>t2)
t1.showTime();
else
t2.showTime();
system("pause");
}