forked from exercism/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
58 lines (49 loc) · 949 Bytes
/
Copy pathexample.cpp
File metadata and controls
58 lines (49 loc) · 949 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
58
#include "clock.h"
#include <iomanip>
#include <sstream>
using namespace std;
namespace date_independent
{
clock& clock::plus(int minutes)
{
minute_ += minutes;
if (minute_ > 60) {
hour_ += (minute_/60);
hour_ %= 24;
minute_ %= 60;
}
return *this;
}
clock& clock::minus(int minutes)
{
minute_ -= minutes;
while (minute_ < 0) {
--hour_;
minute_ += 60;
}
while (hour_ < 0) {
hour_ += 24;
}
return *this;
}
clock::operator string() const
{
ostringstream str;
str << setw(2) << setfill('0') << hour_ << ':' << setw(2) << setfill('0') << minute_;
return str.str();
}
clock::clock(int hour, int minute)
: hour_(hour),
minute_(minute)
{
}
clock clock::at(int hour, int minute /*= 0*/)
{
return clock(hour, minute);
}
bool clock::operator==(const clock& rhs) const
{
return hour_ == rhs.hour_
&& minute_ == rhs.minute_;
}
}