-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.cpp
56 lines (45 loc) · 1.26 KB
/
Account.cpp
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
#include "Account.h"
int Account::nextAccountNumber = 1000;
Account::Account(const std::string& name, float initialDeposit) {
accountNumber = new int(nextAccountNumber++);
balances.push_back(initialDeposit); // initializes balance with initial deposit amount
customerName = name; // set customer name
}
Account::~Account() {}
Account &Account::operator=(const Account &other) {
if (this != &other) {
this->accountNumber = other.accountNumber;
this->customerName = other.customerName;
this->balances = other.balances;
}
return *this;
}
int Account::getAccountNumber() const {
return *accountNumber;
}
std::string Account::getCustomerName() const {
return customerName;
}
std::vector<float> Account::getBalances() const {
return balances;
}
void Account::setCustomerName(const std::string &name) {
customerName = name;
}
void Account::deposit(float amount) {
balances[0] += amount;
}
bool Account::withdraw(float amount) {
if (balances[0] >= amount) {
balances[0] -= amount;
return true;
} else {
return false; // Insufficient funds
}
}
// fast transfer using overloaded operator
Account &Account::operator+=(Account &other) {
other.balances[0] += 40.0;
this->balances[0] -= 40.0;
return *this;
}