-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_3_5_1.cpp
More file actions
69 lines (55 loc) · 1.6 KB
/
Copy pathex_3_5_1.cpp
File metadata and controls
69 lines (55 loc) · 1.6 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
#include <iostream>
using namespace std;
class BankAccount {
public:
float getAccountBalance() {
return accountBalance;
}
void deposit(float amount) {
accountBalance += amount;
}
void withdraw(float request) {
double newBalance = accountBalance - request;
if (newBalance <= 0){
return; // Don't withdraw anything, because the balance would be invalid
cout <<"your balance is too low to withdraw this ammount!"<< endl;
}
else if(newBalance < minBalance) {
if(newBalance <= fee) { // They can't afford the fee
return; // Don't withdraw anything, because the balance would be negative
cout<<"you cannot afford the minimum balance fee on this withdrawa"<< endl;
}
else {
accountBalance = newBalance - fee; // Update the balance, but subtract a fee
}
}
else{
accountBalance = newBalance; // Update the balance
}
}
BankAccount() {
accountNumber = 0;
accountBalance = 0.0;
fee = 50.0;
minBalance = 100.0;
name = "";
address = "";
}
private:
int accountNumber;
float accountBalance;
string name;
string address;
float minBalance;
float fee;
};
int main(){
float withdrawRequest;
BankAccount myAccount;
myAccount.deposit(1000.00);
cout << "Hello customer, please enter the amount you would like to withdraw: ";
cin >> withdrawRequest;
myAccount.withdraw(withdrawRequest);
cout << "Your remaining balance is : " << myAccount.getAccountBalance() << endl;
return 0;
}