-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM.cxx
53 lines (45 loc) · 1.26 KB
/
ATM.cxx
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
#include "ATM.hxx"
#include "BaseDisplay.hxx"
ATM::ATM(Bank* bank, BaseDisplay* display)
{
myBank = bank;
myDisplay = display;
}
void ATM::viewAccount(int accountNumber, string password)
{
if ( !(myCurrentAccount = myBank->getAccount(accountNumber, password)) )
{
myDisplay->showInfoToUser("Invalid account");
}
}
void ATM::fillUserRequest(UserRequest request, double amount)
{
if (myCurrentAccount)
switch (request)
{
case REQUEST_BALANCE:
showBalance(); break;
case REQUEST_DEPOSIT:
makeDeposit(amount); break;
case REQUEST_WITHDRAW:
withdraw(amount); break;
}
}
void ATM::showBalance()
{
double bal = myCurrentAccount->getBalance();
myDisplay->showInfoToUser("Current Balance");
myDisplay->showBalance(bal);
}
void ATM::makeDeposit(double amount)
{
double bal = myCurrentAccount->deposit(amount);
myDisplay->showInfoToUser("Updated Balance");
myDisplay->showBalance(bal);
}
void ATM::withdraw(double amount)
{
double bal = myCurrentAccount->deposit(amount * -1.0);
myDisplay->showInfoToUser("Updated Balance");
myDisplay->showBalance(bal);
}