forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 227
/
TestBankAccount.cpp.html
executable file
·177 lines (148 loc) · 40.3 KB
/
TestBankAccount.cpp.html
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
<pre style='color:#000000;background:#ffffff;'><span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '><</span><span style='color:#40015a; '>iostream</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '><</span><span style='color:#40015a; '>string</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '><</span><span style='color:#40015a; '>stdlib.h</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '><</span><span style='color:#40015a; '>cmath</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '><</span><span style='color:#40015a; '>iomanip</span><span style='color:#800000; '>></span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>"</span><span style='color:#40015a; '>bankAccount.h</span><span style='color:#800000; '>"</span>
<span style='color:#800000; font-weight:bold; '>using</span> <span style='color:#800000; font-weight:bold; '>namespace</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>string</span> options<span style='color:#808030; '>[</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Quit</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
<span style='color:#800000; '>"</span><span style='color:#0000e6; '>Create Account</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
<span style='color:#800000; '>"</span><span style='color:#0000e6; '>Deposit</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
<span style='color:#800000; '>"</span><span style='color:#0000e6; '>Withdraw</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
<span style='color:#800000; '>"</span><span style='color:#0000e6; '>View Balance</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
<span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>int</span> <span style='color:#800000; font-weight:bold; '>const</span> n_choice <span style='color:#808030; '>=</span> <span style='color:#008c00; '>5</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>int</span> menu<span style='color:#808030; '>(</span><span style='color:#603000; '>string</span> option<span style='color:#808030; '>[</span><span style='color:#808030; '>]</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>int</span> n_opt<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>bool</span> is_double<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#603000; '>string</span><span style='color:#808030; '>&</span> s<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>double</span> sanitize<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#603000; '>string</span><span style='color:#808030; '>&</span> s<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>int</span> <span style='color:#400000; '>main</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#603000; '>string</span> response<span style='color:#800080; '>;</span>
bankAccount<span style='color:#808030; '>*</span> account <span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>double</span> previousAmount<span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> fixed<span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>setprecision</span><span style='color:#808030; '>(</span><span style='color:#008c00; '>2</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>--------------------------------------------------</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>This test harness operates with one bank account</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span>
<span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Use the menu options to manipulate it</span><span style='color:#0f69ff; '>\n</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>while</span><span style='color:#808030; '>(</span><span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>int</span> option <span style='color:#808030; '>=</span> menu<span style='color:#808030; '>(</span>options<span style='color:#808030; '>,</span> n_choice<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>switch</span><span style='color:#808030; '>(</span>option<span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>case </span><span style='color:#008c00; '>1</span><span style='color:#e34adc; '>:</span> <span style='color:#696969; '>// quit</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Do you really want to quit? (y/n) > </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>response<span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'y'</span> <span style='color:#808030; '>|</span><span style='color:#808030; '>|</span> response<span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'Y'</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span> <span style='color:#696969; '>// Normal Exit</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>account <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>delete</span> account<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>case </span><span style='color:#008c00; '>2</span><span style='color:#e34adc; '>:</span> <span style='color:#696969; '>// new accont</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>account <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>delete</span> account<span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Do you want to initialize it with an amount (y/n)? > </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>response<span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'y'</span> <span style='color:#808030; '>&</span><span style='color:#808030; '>&</span> response<span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'Y'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Current balance is: $0.00</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
account <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> bankAccount<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#696969; '>// accept elements</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Enter the amount you would like your bank account to have.</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>The amount will be rounded to the second decimal place: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>while</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>!</span> is_double<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Please input a valid numeric: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
account <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> bankAccount<span style='color:#808030; '>(</span>sanitize<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Current balance is: $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>case </span><span style='color:#008c00; '>3</span><span style='color:#e34adc; '>:</span> <span style='color:#696969; '>// Deposit</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>account <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Create an account first.</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>You currently have $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> in your account</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span>
<span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Enter how much you would like to deposit: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>while</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>!</span> is_double<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Please input a valid numeric: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
previousAmount <span style='color:#808030; '>=</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>deposit<span style='color:#808030; '>(</span>sanitize<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span><span style='color:#808030; '>(</span>previousAmount <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>No money deposited into your account.</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>The new balance is: $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>case </span><span style='color:#008c00; '>4</span><span style='color:#e34adc; '>:</span> <span style='color:#696969; '>// Withdraw</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>account <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Create an account first.</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>You currently have $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> in your account</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span>
<span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Enter how much you would like to withdraw: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>while</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>!</span> is_double<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Please input a valid numeric: </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> response<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
previousAmount <span style='color:#808030; '>=</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>withdraw<span style='color:#808030; '>(</span>sanitize<span style='color:#808030; '>(</span>response<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>previousAmount <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>No money was taken out of your account.</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>The new balance is: $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>case </span><span style='color:#008c00; '>5</span><span style='color:#e34adc; '>:</span> <span style='color:#696969; '>// View balance</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>account <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#7d0045; '>NULL</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Create an account first.</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Current balance is: $</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> account<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>getBalance<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>break</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>int</span> menu<span style='color:#808030; '>(</span><span style='color:#603000; '>string</span> option<span style='color:#808030; '>[</span><span style='color:#808030; '>]</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>int</span> n_opt<span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>int</span> choice<span style='color:#808030; '>,</span> i<span style='color:#800080; '>;</span>
<span style='color:#603000; '>string</span> input<span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> - - - - - - MENU - - - - - -</span><span style='color:#0f69ff; '>\n</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>for</span> <span style='color:#808030; '>(</span>i <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span> i <span style='color:#808030; '><</span> n_opt<span style='color:#800080; '>;</span> <span style='color:#808030; '>+</span><span style='color:#808030; '>+</span>i<span style='color:#808030; '>)</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#808030; '>(</span>i<span style='color:#808030; '>+</span><span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> - </span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> option<span style='color:#808030; '>[</span>i<span style='color:#808030; '>]</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> - - - - - - - - - - - - - - -</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>while</span> <span style='color:#808030; '>(</span>input<span style='color:#808030; '>.</span>empty<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '> Enter number of choice > </span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#603000; '>cin</span> <span style='color:#808030; '>></span><span style='color:#808030; '>></span> input<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span><span style='color:#603000; '>isdigit</span><span style='color:#808030; '>(</span>input<span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
choice <span style='color:#808030; '>=</span> <span style='color:#603000; '>atoi</span><span style='color:#808030; '>(</span>input<span style='color:#808030; '>.</span>c_str<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>choice <span style='color:#808030; '><</span><span style='color:#808030; '>=</span> n_opt <span style='color:#808030; '>&</span><span style='color:#808030; '>&</span> choice <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>return</span> choice<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span> <span style='color:#800000; font-weight:bold; '>else</span> <span style='color:#800080; '>{</span> <span style='color:#696969; '>/* choice out of range */</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Your response MUST be between 1 and </span><span style='color:#800000; '>"</span>
<span style='color:#808030; '><</span><span style='color:#808030; '><</span> n_opt <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
input <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span> <span style='color:#800000; font-weight:bold; '>else</span> <span style='color:#800080; '>{</span> <span style='color:#696969; '>/* Non-numeric input, ignore */</span>
<span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\t</span><span style='color:#0000e6; '>Your response MUST be a number!</span><span style='color:#0f69ff; '>\n</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
input <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#008c00; '>1</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>bool</span> is_double<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#603000; '>string</span><span style='color:#808030; '>&</span> s<span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>char</span><span style='color:#808030; '>*</span> end<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>double</span> val <span style='color:#808030; '>=</span> <span style='color:#603000; '>strtod</span><span style='color:#808030; '>(</span>s<span style='color:#808030; '>.</span>c_str<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>&</span>end<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#696969; '>// make sure end is not the start of the string nor null terminate</span>
<span style='color:#696969; '>// make sure val is not HUGE_VAL, meaning the num is out of double's range</span>
<span style='color:#800000; font-weight:bold; '>return</span> end <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> s<span style='color:#808030; '>.</span>c_str<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>&</span><span style='color:#808030; '>&</span> <span style='color:#808030; '>*</span>end <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#0000e6; '>'\0'</span> <span style='color:#808030; '>&</span><span style='color:#808030; '>&</span> val <span style='color:#808030; '>!</span><span style='color:#808030; '>=</span> HUGE_VAL<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
<span style='color:#800000; font-weight:bold; '>double</span> sanitize<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#603000; '>string</span><span style='color:#808030; '>&</span> s<span style='color:#808030; '>)</span><span style='color:#800080; '>{</span>
<span style='color:#800000; font-weight:bold; '>char</span><span style='color:#808030; '>*</span> end<span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>double</span> amount <span style='color:#808030; '>=</span> <span style='color:#603000; '>strtod</span><span style='color:#808030; '>(</span>s<span style='color:#808030; '>.</span>c_str<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>&</span>end<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
amount <span style='color:#808030; '>=</span> round<span style='color:#808030; '>(</span>amount <span style='color:#808030; '>*</span> <span style='color:#008000; '>100.0</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>/</span> <span style='color:#008000; '>100.0</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>amount <span style='color:#808030; '><</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span> amount <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span>
<span style='color:#800000; font-weight:bold; '>return</span> amount<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>
</pre>