-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.cpp
More file actions
37 lines (32 loc) · 1.05 KB
/
Copy pathBankAccount.cpp
File metadata and controls
37 lines (32 loc) · 1.05 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
#include "BankAccount.h"
#include <iostream>
BankAccount::BankAccount(std::string accountNumber, std::string accountHolderName, double initialBalance)
: accountNumber(accountNumber), accountHolderName(accountHolderName), balance(initialBalance) {}
std::string BankAccount::getAccountNumber() const {
return accountNumber;
}
std::string BankAccount::getAccountHolderName() const {
return accountHolderName;
}
double BankAccount::getBalance() const {
return balance;
}
//get the balance
void BankAccount::deposit(double amount) {
if (amount > 0) {
balance += amount;
std::cout << "Deposited: " << amount << std::endl;
} else {
std::cout << "Invalid amount. Deposit failed." << std::endl;
}
}
bool BankAccount::withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
std::cout << "Withdrew: " << amount << std::endl;
return true;
} else {
std::cout << "Invalid amount or insufficient funds. Withdrawal failed." << std::endl;
return false;
}
}