-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.cpp
executable file
·198 lines (168 loc) · 3.77 KB
/
ATM.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
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
#include "ATM.h"
#include <iostream>
using namespace std;
ATM::ATM()
{
PINAttempts = 0;
cCustomer = NULL;
CheckingAccount = NULL;
SavingsAccount = NULL;
}
void ATM::MainMenu(BankData& data)
{
int pin;
bool bFound = false;
int i=0;
cout << "Welcome to the ATM" << endl
<< "=================================" << endl
<< "Enter your PIN #: ";
while (!bFound && PINAttempts <= 3)
{
cin >> pin;
if (cin.fail())
{
cout << "Not a valid PIN #" << endl;
cin.clear();
cin.ignore();
return;
}
for (i=0;i<data.GetRecordCount();++i)
{
if (ConfirmPIN(data.GetCustomer(i),pin))
{
bFound = true;
break;
}
}
if (bFound)
break;
cout << "Incorrect PIN. Try again: ";
}
if (bFound)
{
cCustomer = &data.GetCustomer(i);
CheckingAccount = &data.GetCustomer(i).GetCheckingAccount();
SavingsAccount = &data.GetCustomer(i).GetSavingsAccount();
}
else
{
cout << "Too many incorrect entries" << endl;
Exit();
}
string command;
cout << "Enter a command" << endl
<< "DisplayBalances" << endl
<< "Deposit" << endl
<< "Withdrawl" << endl
<< "Transfer" << endl
<< "Exit" << endl
<< "Command: ";
cin >> command;
cin.ignore();
if (command.compare("DisplayBalances") == 0)
{
DisplayBalances(*cCustomer);
}
else if (command.compare("Deposit") == 0)
{
int acc;
double amt;
cout << "How much would you like to deposit: ";
cin >> amt;
cin.ignore();
cout << "Which account would you like to deposit into (1 - checking, 2 - savings): ";
cin >> acc;
cin.ignore();
switch(acc)
{
case 1:
cCustomer->CheckingDeposit(amt);
break;
case 2:
cCustomer->SavingsDeposit(amt);
break;
}
cout << "Deposit complete" << endl;
}
else if (command.compare("Withdrawl") == 0)
{
int acc;
double amt;
cout << "How much would you like to withdraw: ";
cin >> amt;
cin.ignore();
cout << "Which account would you like to withdraw from (1 - checking, 2 - savings): ";
cin >> acc;
cin.ignore();
if (acc == 1)
{
if (cCustomer->GetCheckingBal()-amt < 0)
cout << "Insufficient funds" << endl;
else
cCustomer->CheckingWithdraw(amt);
}
else if (acc == 2)
{
if (cCustomer->GetSavingsBal()-amt < 0)
cout << "Insufficient funds" << endl;
else
cCustomer->SavingsWithdraw(amt);
}
cout << "Withdrawl complete" << endl;
}
else if (command.compare("Transfer") == 0)
{
int acc;
double amt;
cout << "How much would you like to transfer: ";
cin >> amt;
cin.ignore();
cout << "Which account would you like to withdraw from (1 - checking, 2 - savings): ";
cin >> acc;
cin.ignore();
if (acc == 1)
{
if (!TransferFunds(cCustomer->GetCheckingAccount(),cCustomer->GetSavingsAccount(),amt))
cout << "Insufficient funds" << endl;
else
cout << "Transfer complete" << endl;
}
else if (acc == 2)
{
if (!TransferFunds(cCustomer->GetSavingsAccount(),cCustomer->GetCheckingAccount(),amt))
cout << "Insufficient funds" << endl;
else
cout << "Transfer complete" << endl;
}
}
else if (command.compare("Exit") == 0)
Exit();
}
void ATM::DisplayBalances(Customer myCustomer)
{
cout << "Your Checking Account Balance: $" << setprecision(2) << fixed << CheckingAccount->GetBalance() << endl;
cout << "Your Savings Account Balance: $" << setprecision(2) << fixed << SavingsAccount->GetBalance() << endl;
cout << endl;
}
void ATM::Exit()
{
cout << "Thank you for using the ATM" << endl;
exit(0);
}
bool ATM::ConfirmPIN(Customer myCustomer, int pin)
{
if (myCustomer.GetPIN() == pin)
return true;
else
++PINAttempts;
}
bool ATM::TransferFunds(Account& SourceAccount, Account& DestinationAccount, double Amount)
{
if (SourceAccount.Transfer(DestinationAccount,Amount) == 0)
return true;
return false;
}
void ATM::SetCustomer(Customer* e)
{
cCustomer = e;
}