-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime_Main.cpp
More file actions
110 lines (99 loc) · 2.27 KB
/
Time_Main.cpp
File metadata and controls
110 lines (99 loc) · 2.27 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
107
108
109
110
// ===========================================================================
// Time_Main.cpp
// ===========================================================================
#include "Time.h"
static void testCtors()
{
Time t1;
std::cout << t1 << std::endl;
Time t2(0, 30, 12);
std::cout << t2 << std::endl;
Time t3("09:30:00");
std::cout << t3 << std::endl;
Time t4(24 * 60 * 60 - 1);
std::cout << t4 << std::endl;
}
static void testAdd()
{
// testing 'Add'
Time t1(0, 0, 12);
Time t2(33, 33, 3);
for (int i = 0; i < 5; i++)
{
t1.add(t2);
std::cout << t1 << std::endl;
}
}
static void testDiff()
{
// testing 'Diff'
Time t1;
Time t2("23:59:59");
Time t3 = t1.diff(t2);
std::cout << t3 << std::endl;
t3 = t2.diff(t1);
std::cout << t3 << std::endl;
}
static void testArithmeticOperators()
{
// testing operators
Time t1(15, 30, 6);
Time t2 = t1 + t1;
std::cout << t2 << std::endl;
t2 += t1;
std::cout << t2 << std::endl;
t2 -= 120;
std::cout << t2 << std::endl;
t2 -= t1;
std::cout << t2 << std::endl;
}
static void testIncrementOperators()
{
// testing 'Increment'
Time t(55, 59, 23);
for (int i = 0; i < 8; i++)
{
t.increment();
std::cout << t << std::endl;
}
}
static void testIncrementDecrementOperators()
{
// testing increment/decrement operator
Time t1(0, 0, 12);
Time t2 = t1++;
std::cout << t2 << std::endl;
t2 = ++t1;
std::cout << t2 << std::endl;
t2 = t1--;
std::cout << t2 << std::endl;
t2 = --t1;
std::cout << t2 << std::endl;
}
static void testConversion()
{
Time t;
t = 60 * 60 + 60 + 1;
std::cout << "Time: " << t << std::endl;
std::cout << "Seconds: " << (int)t << std::endl;
}
static void testInputOutput()
{
Time t;
std::cin >> t;
std::cout << t << std::endl;
}
void exerciseTime()
{
testCtors();
testAdd();
testDiff();
testArithmeticOperators();
testIncrementOperators();
testIncrementDecrementOperators();
testConversion();
testInputOutput();
}
// ===========================================================================
// End-of-File
// ===========================================================================