-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn-Tobj.cpp
More file actions
71 lines (65 loc) · 1.54 KB
/
return-Tobj.cpp
File metadata and controls
71 lines (65 loc) · 1.54 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
71
#include <iostream>
#include <conio.h>
using namespace std;
class Time{
private:
int second;
int minute;
int hour;
public:
void setTime(int h, int m, int s){
hour = h;
minute = m;
second = s;
}
Time add(Time T1)
{
Time tempt;
tempt.second = tempt.minute = tempt.hour = 0;
tempt.second = second + T1.second;
if(tempt.second >= 60){
tempt.second = tempt.second - 60;
tempt.minute += 1;
}
tempt.minute = minute + T1.minute;
if(tempt.minute >= 60){
tempt.minute = tempt.minute - 60;
tempt.hour += 1;
}
tempt.hour += hour + T1.hour;
return tempt;
}
Time minus(Time T1)
{
Time tempt;
tempt.second = tempt.minute = tempt.hour = 0;
tempt.second = second - T1.second;
if(tempt.second < 0){
tempt.second = tempt.second + 60;
tempt.minute --;
}
tempt.minute = minute - T1.minute;
if(tempt.minute < 0){
tempt.minute = tempt.minute + 60;
tempt.hour --;
}
tempt.hour += hour + T1.hour;
if(tempt.hour < 0){
tempt.hour += 12;
}
return tempt;
}
void displayTime(){
cout << "hour: " << hour << " minute: " << minute << "seconds: "<<second<< endl;
}
};
int main()
{
Time T1, T2, T3;
T1.setTime(10, 2,12);
T2.setTime(30, 10,45);
T3 = T1.add(T2);
T3.displayTime();
getch();
return 0;
}