-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTime.cpp
More file actions
106 lines (84 loc) · 1.49 KB
/
Time.cpp
File metadata and controls
106 lines (84 loc) · 1.49 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "Time.h"
Time::Time(int d, int h)
{
day = d;
hour = h;
}
// Amember Function for reading Time form File
void Time::read_time(ifstream& cin)
{
int h, d;
cin >> d;
cin.ignore(1);
cin >> h;
day = d;
hour = h;
}
//int Time::operator-(Time time)
//{
// int h =abs( hour - time.hour);
// int d = abs(day - time . day);
// return h + d * 24;
//}
bool Time::operator<=(Time t2)
{
if (day < t2.getday()) return true;
else if (hour <= t2.gethour()&&day==t2.getday()) return true;
return false;
}
bool Time::operator>=(Time t2)
{
if (day > t2.getday()) return true;
else if (hour >= t2.gethour() && day == t2.getday()) return true;
return false;
}
void Time::sethour(int h)
{
hour = h;
}
void Time::setday(int d)
{
day = d;
}
int Time::gethour()
{
return hour;
}
int Time::getday()
{
return day;
}
Time::Time() {}
void Time::increase()
{
hour += 1;
if (hour >= 24)
{
hour -= 24;
day++;
}
}
bool Time::operator==(Time t2)
{
if (getday() == t2.getday() && gethour() == t2.gethour()) return true;
else return false;
}
void Time::write_time(ofstream& cout)
{
cout << this->day << ':' << this->hour;
}
Time Time:: operator +(Time t2)
{
Time sum_t;
if ((this->hour + t2.hour) > 24)
{
sum_t.sethour((this->hour + t2.hour) - 24);
sum_t.setday(this->day + t2.day + 1);
}
else
{
sum_t.sethour(this->hour + t2.hour);
sum_t.setday(this->day + t2.day);
}
return sum_t;
}