-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.cpp
57 lines (45 loc) · 1.12 KB
/
time.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
#include<iostream>
#include<bits/stl_pair.h>
using namespace std;
class Time;
Time addTime(Time , Time);
class Time{
private:
int hrs;
int min;
friend Time addTime(Time a , Time b);
public:
Time():hrs(0),min(0){
return;
}
Time(int hour ,int minutes):hrs(hour),min(minutes){
return;
}
~Time(){
return ;
}
std::pair<int,int> getData(){
return make_pair(hrs,min);
}
void setData(int hour, int minutes){
this->hrs = hour;
this->min = minutes;
}
};
Time addTIme(Time a, Time b){
int hours = a.hrs + b.hrs;
int minutes = a.min + b.min;
if(minutes >= 60){
minutes = minutes%60;
hours = hours + minutes/60;
}
Time output(hours,minutes);
return output;
}
int main(){
Time a(8,15), b(1,20);
Time output = addTime(a,b);
std:: pair<int,int> p = output.getData();
cout<<p.first<<" "<<p.second<<endl;
return 0;
}