forked from Yash-Raj-Singh/2nd_sem_oops_files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime2.cpp
73 lines (53 loc) · 709 Bytes
/
time2.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
64
65
66
67
68
69
70
71
72
73
#include <iostream>
using namespace std;
class time
{
public:
int h, m, s, a, b, c;
time()
{
h=0, m=0, s=0;
}
void getdata()
{
cout<<"Enter the value of Hour : ";
cin>>h;
cout<<endl;
cout<<"Enter the value of Minute : ";
cin>>m;
cout<<endl;
cout<<"Enter the value of Second : ";
cin>>s;
cout<<endl;
}
void add(time t1, time t2)
{
s = t1.s + t2.s;
m = t1.m + t2.m;
h = t1.h + t2.h;
if(s>=60)
{
s = s - 60;
m++;
}
if(m>=60)
{
m = m - 60;
h++;
}
if(h>=24)
{
cout<<"error";
cout<<"\n";
}
cout<<h<<":"<<m<<":"<<s<<"\n";
}
};
int main()
{
time t1, t2, t3;
t1.getdata();
t2.getdata();
t3.add(t1, t2);
return 0;
}