-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.cpp
More file actions
164 lines (137 loc) · 3.03 KB
/
Copy pathAccount.cpp
File metadata and controls
164 lines (137 loc) · 3.03 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
/*
Account.cpp
Teng Zhao: 40089560
Thomas Flynn: 40034877
*/
#include "Account.h"
#include "Customer.h"
Account::Account() {
accountNumber = " ";
balance = 0;
fee = 0;
for (auto& i : ownerList) {
i = nullptr;
}
}
Account::Account(string a, double b, double c) {
accountNumber = a;
balance = b;
fee = c;
for (auto& i : ownerList) {
i = nullptr;
}
}
void Account::setBalance(double a) {
balance = a;
}
void Account::setFee(double a) {
fee = a;
}
string Account::getAccountNumber() {
return accountNumber;
}
void Account::addOwner(Customer* &a) {
bool isOwnerThere = false;
bool success = false;
for (auto& i : ownerList) { //Check if customer is already in ownerList
if (i != nullptr) {
if (a->getCustomerID() == i->getCustomerID()) {
cout << "Account already has this owner." << endl;
isOwnerThere = true;
break;
}
}
}
if (isOwnerThere == false) {
for (auto& i : ownerList) {
if (i == nullptr) {
if (a->addAccount1(this)) { //add account to the customer's accountList
i = a;
success = true;
break;
}
}
}
}
if (success == true) {
cout << "Success: Owner added." << endl;
}
else if (success == false) {
cout << "Fail: All customer slot have been set, please remove a customer and try again." << endl;
}
}
bool Account::addOwner1(Customer* a) { //used only by addAccount member function located in Customer.cpp
bool isOwnerThere = false;
for (auto&i : ownerList) { //Check if customer is already in ownerList array
if (i != nullptr) {
if (i->getCustomerID() == a->getCustomerID()) {
isOwnerThere = true;
return true;
}
}
}
if (isOwnerThere == false) { //if customer is not in array then adds the customer to it
for (auto& i : ownerList) {
if (i == nullptr) {
i = a;
return true;
}
}
}
return false;
}
void Account::removeOwner(string a) {
bool isOwnerThere = false;
bool success = false;
for (auto& i : ownerList) { //Check if owner is in ownerList
if (i != nullptr) {
if (i->getCustomerID() == a) {
isOwnerThere = true;
break;
}
}
}
if (isOwnerThere == true) {
for (auto&i : ownerList) {
if (i != nullptr) {
if (i->getCustomerID() == a) {
if (i->removeAccount(this)) {
i = nullptr;
success = true;
}
break;
}
}
}
}
if (success == true) {
cout << "Success: Customer/owner removed." << endl;
}
else if(success == false) {
cout << "Customer does not own this account/ the account does not exist." << endl;
}
}
bool Account::removeOwner(Customer* a) { //used only by removeAccount funciton in Customer.cpp only (was "removeOwner1()")
for (auto& i : ownerList) { //remove owner from ownerList
if (i != nullptr) {
if (i->getCustomerID() == a->getCustomerID()) {
i = nullptr;
return true;
}
}
}
return false;
}
void Account::printOwner() const{
for (auto& i : ownerList) {
if (i != nullptr) {
i->printCustomer();
}
}
}
Customer* Account::returnOwnerList(int a) {
return this->ownerList[a];
}
int Account::sizeOfOwnerList() {
return ownerList.size();
}