-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime.cpp
executable file
·66 lines (57 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
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <iomanip>
#include "Time.h"
using namespace std;
// Constructor Function
Time::Time()
{
// value of 0 assigned to 3 integers in class 'Time'
hour = 0;
minute = 0;
second = 0;
}
Time::Time(int h, int m, int s)
{
setTime(h, m, s);
}
void Time::setTime(int h, int m, int s)
{
// runs thru constructor functions to validate inputs.
// after validation, assigns input to 'class' integers.
setHour(h);
setMinute(m);
setSecond(s);
}
void Time::setHour(int h)
{
if (h >= 0 && h <= 23)
{
hour = h;
}
}
void Time::setMinute(int m)
{
if (m >= 0 && m <= 59)
{
minute = m;
}
}
void Time::setSecond(int s)
{
if (s >= 0 && s <= 59)
{
second = s;
}
}
void Time::printMilitary() // outputs military time
{
cout << setfill('0') << setw(2) << hour
<< setfill('0') << setw(2) << minute;
}
void Time::printStandard() // outputs standard time
{
cout << (hour > 12 ? hour - 12 : hour) << ":"
<< setfill('0') << setw(2) << minute << ":"
<< setfill('0') << setw(2) << second
<< (hour >= 12 ? " pm" : " am"); //Figure out am/pm
}