-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranch.cpp
More file actions
163 lines (138 loc) · 3.39 KB
/
Copy pathBranch.cpp
File metadata and controls
163 lines (138 loc) · 3.39 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
/*
Branch.cpp
Teng Zhao: 40089560
Thomas Flynn: 40034877
*/
#include "Branch.h"
Branch::Branch() {
branchID = " ";
branchAddress = " ";
branchNumber = " ";
for (auto& i : accountList) {
i = nullptr;
}
}
Branch::Branch(string a, string b, string c) {
branchID = a;
branchAddress = b;
branchNumber = c;
for (auto& i : accountList) {
i = nullptr;
}
}
void Branch::setBranchID(string a) {
branchID = a;
}
void Branch::setBranchAddress(string a) {
branchAddress = a;
}
void Branch::setBranchNumber(string a) {
branchNumber = a;
}
void Branch::addAccount(Account* a){
bool isAccountThere = false;
bool success = false;
for (auto& i : accountList) { //Check if account already in accoutList
if (i != nullptr) {
if (i->getAccountNumber() == a->getAccountNumber()) {
cout << "Branch already has this account." << endl;
isAccountThere = true;
break;
}
}
}
if (isAccountThere == false) {
for (auto&i : accountList) {
if (i == nullptr) {
i = a;
success = true;
break;
}
}
}
if(success == true) {
cout << "Success: Account added to Branch." << endl;
}
else if(success == false) {
cout << "Fail: All accounts slot have been set, please remove an account and try again." << endl;
}
}
void Branch::removeAccount(string a){
bool isAccountThere = false;
bool success = false;
for (auto& i : accountList) { //Check if account is in accountList
if (i != nullptr) {
if (i->getAccountNumber() == a) {
isAccountThere = true;
break;
}
}
}
if (isAccountThere == true) {
for (auto &i : accountList) {
if (i != nullptr) {
if (i->getAccountNumber() == a) {
i = nullptr; //remove account from accountList
success = true;
break;
}
}
}
}
if (success == true) {
cout << "Success: Account removed from branch." << endl;
}
else if (success == false) {
cout << "Branch does not have Account/ Account does not exit." << endl;
}
}
void Branch::listAccount() {
cout << "--- Account list for Branch: " << this->getBranchID() << " ---" << endl;
for (auto& i : accountList) {
if (i != nullptr) {
cout << " - " << i->getAccountNumber() << endl;
}
}
}
void Branch::listCustomer(){ //I am not remove duplicated customers
cout << "--- Customer list for Branch: " << this->getBranchID() << " ---" << endl;
for (auto& i : accountList) {
if (i != nullptr) {
for (int k = 0; k < i->sizeOfOwnerList(); k++) {
if (i->returnOwnerList(k) != nullptr) {
cout << " - " << i->returnOwnerList(k)->getCustomerFirst() << endl;
}
}
}
}
//go through each account and print out its owner's ignore if duplication use function returnOwnerList in Account.cpp
}
bool Branch::searchCustomer(string a){ //this might not work
for (auto& i : accountList) {
if (i != nullptr) {
for (int k = 0; k < i->sizeOfOwnerList(); k++) {
if (i->returnOwnerList(k) != nullptr) {
if (i->returnOwnerList(k)->getCustomerID() == a)
return true;
}
}
}
}
return false;
}
void Branch::printBranch() {
cout << "----- Branch -----" << endl;
cout << "ID: " << branchID << endl;
cout << "Address: " << branchAddress << endl;
cout << "Phone Number: " << branchNumber << endl;
cout << "Accounts within branch" << endl;
}
string Branch::getBranchID() const {
return branchID;
}
Account* Branch::returnAccountList(int a) {
return this->accountList[a];
}
int Branch::sizeOfAccountList() {
return accountList.size();
}