-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.cpp
More file actions
48 lines (32 loc) · 1.17 KB
/
BankAccount.cpp
File metadata and controls
48 lines (32 loc) · 1.17 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
#include "BankAccount.h"
using std::cout;
using std::endl;
using std::string;
using std::to_string;
BankAccount::BankAccount(string account_id, float balance):
account_id (account_id), balance(balance) {
cout << " Starting balance is: " << balance << endl;
}
void BankAccount::deduct_service_charge(TransactionType transaction_type) {
if(transaction_type == TransactionType::Cheque) {
balance = balance - 2;
} else if (transaction_type == TransactionType::Cash) {
balance = balance - 1;
} else if (transaction_type == TransactionType::Electronic) {
balance = balance - 0.5;
}
}
bool BankAccount::withdraw(TransactionType transaction_type, float amount) {
if (amount <= balance) {
balance = balance - amount;
deduct_service_charge(transaction_type);
cout << " Withdraw " << amount << " Balance is: " << balance << endl;
return true;
}
return false;
}
void BankAccount::deposit(TransactionType transaction_type, float amount) {
balance = balance + amount;
deduct_service_charge(transaction_type);
cout << " Deposited " << amount << " Balance is: " << balance << endl;
}