-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.cpp
More file actions
215 lines (181 loc) · 4.49 KB
/
Copy pathCustomer.cpp
File metadata and controls
215 lines (181 loc) · 4.49 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
/*
Customer.cpp
Teng Zhao: 40089560
Thomas Flynn: 40034877
*/
#include "Customer.h"
#include "Account.h"
Customer::Customer() {
customerID = " ";
firstName = " ";
lastName = " ";
customerAddress = " ";
customerNumber = " ";
customerEmail = " ";
for (auto& i: accountList) {
i = nullptr;
}
}
Customer::Customer(string a, string b, string c, string d, string e, string f) {
customerID = a;
firstName = b;
lastName = c;
customerAddress = d;
customerNumber = e;
customerEmail = f;
for (auto& i : accountList) {
i = nullptr;
}
}
void Customer::setFirstName(string a) {
firstName = a;
}
void Customer::setLastName(string a) {
lastName = a;
}
void Customer::setCustomerAddress(string a) {
customerAddress = a;
}
void Customer::setCustomerNumber(string a) {
customerNumber = a;
}
void Customer::setCustomerEmail(string a) {
customerEmail = a;
}
void Customer::addAccount(Account* a) {
bool isAccountThere = false;
bool success = false;
for (auto& i : accountList) { //Check if account already in accoutList
if (i != nullptr) {
if (a->getAccountNumber() == i->getAccountNumber()) {
cout << "Customer already has this account." << endl;
isAccountThere = true;
break;
}
}
}
if (isAccountThere == false) {
for (auto&i : accountList) {
if (i == nullptr) {
if (a->addOwner1(this)) { //add customer to the account's ownerList
i = a;
success = true;
break;
}
}
}
}
if (success == true) {
cout << "Success: Account added." << endl;
}
else if (success == false) {
cout << "Fail: All accounts slot have been set, please remove an account and try again." << endl;
}
}
bool Customer::addAccount1(Account* a) { //used only by addOwner member function located in Account.cpp
bool isAccountThere = false;
for (auto& i : accountList) { //Check if account is already in accountList array
if (i != nullptr) {
if (i->getAccountNumber() == a->getAccountNumber()) {
isAccountThere = true;
return true;
}
}
}
if (isAccountThere == false) { //if account is not in array then adds the account to it
for (auto& i : accountList) {
if (i == nullptr) {
i = a;
return true;
}
}
}
return false;
}
void Customer::removeAccount(string a) { //done
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) {
if (i->removeOwner(this)) { //remover owner from ownerList
i = nullptr; //remove account from accountList
success = true;
}
break;
}
}
}
}
if (success == true) {
cout << "Success: Account removed." << endl;
}
else if (success == false) {
cout << "Account does not have owner/ owner does not exit." << endl;
}
}
bool Customer::removeAccount(Account* a) { //used by removeOwner function in Account.cpp only (was "removeAccount1()")
for (auto&i : accountList) { //remove account from accountList
if (i != nullptr) {
if (i->getAccountNumber() == a->getAccountNumber()) {
i = nullptr;
return true;
}
}
}
return false;
}
string Customer::getCustomerID() const{
return customerID;
}
string Customer::getCustomerFirst() const{
return firstName;
}
string Customer::getCustomerLast() const{
return lastName;
}
void Customer::listAccount() const{
for (auto& i : accountList) {
if (i != nullptr) {
cout << i->getAccountNumber() << endl;
}
}
}
void Customer::listChequing() const {
cout << this->getCustomerFirst() << "'s Chequing Account Number(s): " << endl;
for (auto& i : accountList) {
if (i != nullptr) {
if (static_cast<string>(typeid(*i).name()) == "class Chequing") {
cout << "- " << i->getAccountNumber() << endl;
}
}
}
}
void Customer::listSaving() const {
cout << this->getCustomerFirst() << "'s Saving Account Number(s): " << endl;
for (auto& i : accountList) {
if (i != nullptr){
if (static_cast<string>(typeid(*i).name()) == "class Saving") {
cout << "- " << i->getAccountNumber() << endl;
}
}
}
}
void Customer::printCustomer() {
cout << "----- Customer -----" << endl;
cout << "ID: " << customerID << endl;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Address: " << customerAddress << endl;
cout << "Phone Number: " << customerNumber << endl;
cout << "Email: " << customerEmail << endl;
}