-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.cpp
More file actions
77 lines (71 loc) · 2.01 KB
/
Bank.cpp
File metadata and controls
77 lines (71 loc) · 2.01 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
#include <iostream>
#include "Bank.hpp"
#include <cstdlib>
#include <string>
using namespace std;
//default constructor
Bank::Bank() {
numAccounts = 0;
}
string Bank::createAccount(string first_name, string last_name, string pin_number){
Account newAcc = Account(first_name, last_name, pin_number);
if(numAccounts != 200){
bankAccounts[numAccounts] = newAcc;
numAccounts++;
return newAcc.getPin();
}
return "-1";
}
bool Bank::removeAccount(string acc_number){
Account tempAccounts[200];
bool seen = false;
for(int i = 0; i < 200; i++){
if(bankAccounts[i].getAccountNumber() != acc_number){
if(seen){
tempAccounts[i-1] = bankAccounts[i];
}
else{
tempAccounts[i] = bankAccounts[i];
}
}
else{
seen = true;
numAccounts--;
}
}
return seen;
}
bool Bank::withdraw(int amount, string acc_number, string pin_number){
for(int i = 0; i < numAccounts; i++){
if(bankAccounts[i].getAccountNumber() == acc_number){
if(bankAccounts[i].getPin() == pin_number){
if(bankAccounts[i].transaction(-1 * amount)){
return true;
}
}
}
}
return false;
}
bool Bank::deposit(int amount, string acc_number, string pin_number){
for(int i = 0; i < numAccounts; i++){
if(bankAccounts[i].getAccountNumber() == acc_number){
if(bankAccounts[i].getPin() == pin_number){
if(bankAccounts[i].transaction(amount)){
return true;
}
}
}
}
return false;
}
int Bank::getAccountBalance(string acc_number, string pin_number){
for(int i = 0; i < numAccounts; i++){
if(bankAccounts[i].getAccountNumber() == acc_number){
if(bankAccounts[i].getPin() == pin_number){
return bankAccounts[i].getBalance();
}
}
}
return -1;
}