-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWallet_Main.cpp
More file actions
236 lines (194 loc) · 5.38 KB
/
Wallet_Main.cpp
File metadata and controls
236 lines (194 loc) · 5.38 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// ===========================================================================
// Wallet_Main.cpp
// ===========================================================================
#include <iostream>
#include "Wallet.h"
static void test_01_ctors()
{
Wallet empty;
empty.print();
Wallet wallet(123, 45);
wallet.print();
}
static void test_02_ctors()
{
try
{
Wallet wallet("123", "45");
//Wallet wallet("ABC", "45");
//Wallet wallet("123", "DE");
//Wallet wallet("123DE", "45");
//Wallet wallet("123", "45DE");
//Wallet wallet("-123", "45");
//Wallet wallet("123", "-45");
wallet.print();
}
catch (const std::exception& ex)
{
std::cout << "Wrong parameters: " << ex.what() << std::endl;
}
}
static void test_03_toString()
{
Wallet empty;
std::cout << empty.to_string() << std::endl;
Wallet wallet(123, 55);
std::cout << wallet.to_string() << std::endl;
}
static void test_04_add()
{
Wallet wallet1(123, 45);
Wallet wallet2(3, 30);
Wallet wallet3(3, 30);
Wallet wallet4(3, 30);
Wallet wallet5(3, 30);
wallet1.add(wallet2);
std::cout << wallet1 << std::endl;
wallet1.add(wallet3);
std::cout << wallet1 << std::endl;
wallet1.add(wallet4);
std::cout << wallet1 << std::endl;
wallet1.add(wallet5);
std::cout << wallet1 << std::endl;
}
static void test_05_sub()
{
Wallet wallet1(0, 3);
Wallet wallet2(0, 1);
wallet1.sub(wallet2);
std::cout << wallet1 << std::endl;
wallet1.sub(wallet2);
std::cout << wallet1 << std::endl;
wallet1.sub(wallet2);
std::cout << wallet1 << std::endl;
try
{
wallet1.sub(wallet2);
}
catch (const std::invalid_argument& ex)
{
std::cout << ex.what() << std::endl;
}
}
static void test_06_add_sub_euros()
{
Wallet wallet(5);
wallet.add(5);
std::cout << wallet<< std::endl;
wallet.sub(10);
std::cout << wallet << std::endl;
}
static void test_07_comparision()
{
Wallet wallet1(10, 20);
Wallet wallet2(20, 10);
std::cout << std::boolalpha << (wallet1 == wallet1) << std::endl;
std::cout << std::boolalpha << (wallet1 == wallet2) << std::endl;
std::cout << std::boolalpha << (wallet1 != wallet2) << std::endl;
std::cout << std::boolalpha << (wallet1 < wallet2) << std::endl;
std::cout << std::boolalpha << (wallet1 <= wallet2) << std::endl;
std::cout << std::boolalpha << (wallet1 > wallet2) << std::endl;
std::cout << std::boolalpha << (wallet1 >= wallet2) << std::endl;
}
static void test_08_arithmetic_increment_operators()
{
Wallet wallet1(123, 45);
Wallet wallet2(26, 55);
wallet1 += wallet2;
std::cout << wallet1 << std::endl;
wallet1 += 50;
std::cout << wallet1 << std::endl;
wallet1 -= wallet2;
std::cout << wallet1 << std::endl;
wallet1 -= 73;
std::cout << wallet1 << std::endl;
}
static void test_09_increment_operators()
{
Wallet wallet(10);
Wallet wallet1;
std::cout << wallet << std::endl;
wallet1 = ++wallet;
std::cout << wallet1 << std::endl;
wallet1 = --wallet;
std::cout << wallet1 << std::endl;
wallet1 = wallet--;
std::cout << wallet1 << std::endl;
std::cout << wallet << std::endl;
wallet1 = wallet++;
std::cout << wallet1 << std::endl;
std::cout << wallet << std::endl;
}
static void test_10_example_tutorial()
{
Wallet wallet(2, 50);
std::cout << wallet << std::endl;
std::cout << "Wallet contains " << wallet.getEuros() << " euros." << std::endl;
std::cout << "Wallet contains " << wallet.getCent() << " cent." << std::endl;
}
static void test_11_example_tutorial()
{
Wallet wallet(2, 50);
std::cout << wallet << std::endl;
wallet.add(5);
std::cout << wallet << std::endl;
wallet.sub(7);
std::cout << wallet << std::endl;
}
static void test_12_example_tutorial()
{
Wallet wallet(2, 50);
std::cout << wallet << std::endl;
try
{
wallet.sub(3);
}
catch (const std::invalid_argument& ex)
{
std::cout << ex.what() << std::endl;
}
std::cout << wallet << std::endl;
}
static void test_13_example_tutorial()
{
Wallet wallet(2, 50);
std::cout << wallet << std::endl;
wallet += 3;
std::cout << wallet << std::endl;
}
static void test_14_example_tutorial()
{
Wallet wallet1(2, 50);
std::cout << wallet1 << std::endl;
Wallet wallet2(3, 75);
std::cout << wallet2 << std::endl;
if (wallet1 < wallet2) {
std::cout << "Wallet 1 contains less money than Wallet 2" << std::endl;
}
wallet1 = wallet2;
std::cout << wallet1 << std::endl;
std::cout << wallet1 << std::endl;
if (wallet1 == wallet2) {
std::cout << "Wallet 1 contains the same amount of money as Wallet 2." << std::endl;
}
}
void exerciseWallet()
{
test_01_ctors();
test_02_ctors();
test_03_toString();
test_04_add();
test_05_sub();
test_06_add_sub_euros();
test_07_comparision();
test_08_arithmetic_increment_operators();
test_09_increment_operators();
test_10_example_tutorial();
test_11_example_tutorial();
test_12_example_tutorial();
test_13_example_tutorial();
test_14_example_tutorial();
}
// ===========================================================================
// End-of-File
// ===========================================================================