-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.cpp
More file actions
247 lines (214 loc) · 5.14 KB
/
Copy pathBank.cpp
File metadata and controls
247 lines (214 loc) · 5.14 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
237
238
239
240
241
242
243
244
245
246
247
/*
Bank.cpp
Teng Zhao: 40089560
Thomas Flynn: 40034877
*/
#include "Bank.h"
Bank::Bank() {
bankID = " ";
name = " ";
bankAddress = " ";
bankNumber = " ";
for (auto& i : branchList) {
i = nullptr;
}
}
Bank::Bank(string a, string b, string c, string d) {
bankID = a;
name = b;
bankAddress = c;
bankNumber = d;
for (auto& i : branchList) {
i = nullptr;
}
}
void Bank::setName(string a) {
name = a;
}
void Bank::setBankAddress(string a) {
bankAddress = a;
}
void Bank::setBankNumber(string a) {
bankNumber = a;
}
void Bank::addBranch (Branch* a){//add a branch to bank
//add branch pointer to branchList
bool isBranchThere = false;
bool success = false;
for (auto&i : branchList) {//Check if branch already in branchList
if (i != nullptr) {
if (i->getBranchID()==a->getBranchID()) {
cout << "Bank already has this branch." << endl;
isBranchThere = true;
break;
}
}
}
if (isBranchThere == false) {
for (auto&i : branchList) {
if (i == nullptr) {
i = a;
success = true;
break;
}
}
}
if (success == true) {
cout << "Success: Branch added." << endl;
}
else if (success == false) {
cout << "Fail: All Branch slot have been set, please remove a branch and try again." << endl;
}
}
void Bank::removeBranch(string a){//remove a branch from bank
//filter using branchID and remove it from branchList
bool isBranchThere = false;
bool success = false;
for (auto& i : branchList) { //Check if branch is in accountList
if (i != nullptr) {
if (i->getBranchID() == a) {
isBranchThere = true;
break;
}
}
}
if (isBranchThere == true) {
for (auto &i : branchList) {
if (i != nullptr) {
if (i->getBranchID() == a) {
for (int j = 0; j < i->sizeOfAccountList(); j++) {
if (i->returnAccountList(j) != nullptr) {
i->removeAccount(i->returnAccountList(j)->getAccountNumber());
}
}
i = nullptr; //remove branch from branch List
success = true;
break;
}
}
}
}
if (success == true) {
cout << "Success: Branch removed." << endl;
}
else if (success == false) {
cout << "Bank does not have Branch/ Branch does not exit." << endl;
}
}
void Bank::listAccount(string a){//list all the accounts held by a branch
//branch->printAccountList function
bool isBranchThere = false;
for (auto&i : branchList) {
if (i != nullptr) {
if (i->getBranchID() == a) {
i->listAccount();
isBranchThere = true;
break;
}
}
}
if (isBranchThere == false) {
cout << "branchID not found." << endl;
}
}
void Bank::listCustomer(string a){//list all Customers of a branch
//branch->listCustomer function
bool isBranchThere = false;
for (auto&i : branchList) {
if (i != nullptr) {
if (i->getBranchID() == a) {
i->listCustomer(); //the problem is within listCustomer()
isBranchThere = true;
break;
}
}
}
if (isBranchThere == false) {
cout << "branchID not found." << endl;
}
}
void Bank::printBranch(string a){ //Input a brachID and pribnt out it's information
//branch->printBranch function
bool isBranchThere = false;
for (auto&i : branchList) {
if (i != nullptr) {
if (i->getBranchID() == a) {
i->printBranch();
isBranchThere = true;
break;
}
}
}
if (isBranchThere == false) {
cout << "branchID not found." << endl;
}
}
void Bank::printAccount(string a){
//filter through each branch
//in each branch filter through account list for the account number
//branch->accountList->printAccount
bool isAccountThere = false;
for (auto&i : branchList) {
if (i != nullptr) {
for (int j = 0; j < i->sizeOfAccountList(); j++) {
if (i->returnAccountList(j) != nullptr) {
if (i->returnAccountList(j)->getAccountNumber() == a) {
i->returnAccountList(j)->printAccount();
isAccountThere = true;
}
}
}
if(isAccountThere){
break;
}
}
}
if (isAccountThere == false) {
cout << "Account not found." << endl;
}
}
void Bank::printCustomer(string a){
//filter through each branch
//in each branch filter through account list for the ownerList
//ownerList->getCustomerID
bool isCustomerThere = false;
for (auto&i : branchList) {
if (i != nullptr) {
for (int j = 0; j < i->sizeOfAccountList(); j++) {
if (i->returnAccountList(j) != nullptr) {
for (int k = 0; k < i->returnAccountList(j)->sizeOfOwnerList(); k++) {
if (i->returnAccountList(j)->returnOwnerList(k) != nullptr) {
if (i->returnAccountList(j)->returnOwnerList(k)->getCustomerFirst() == a) {
i->returnAccountList(j)->returnOwnerList(k)->printCustomer();
isCustomerThere = true;
break;
}
}
}
if (isCustomerThere) {
break;
}
}
}
if (isCustomerThere) {
break;
}
}
}
if (isCustomerThere == false) {
cout << "Customer not found." << endl;
}
}
void Bank::printBank() {
cout << "----- Bank -----" << endl;
cout << "ID: " << bankID << endl;
cout << "Name: " << name << endl;
cout << "Address: " << bankAddress << endl;
cout << "Phone Number: " << bankNumber << endl;
cout << "Branches within the Bank" << endl;
for (auto&i : branchList) {
if (i != nullptr) {
cout << "- " << i->getBranchID() << endl;
}
}
}