diff options
Diffstat (limited to 'cs162/wk6/friends/bankAccount.cc')
| -rw-r--r-- | cs162/wk6/friends/bankAccount.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cs162/wk6/friends/bankAccount.cc b/cs162/wk6/friends/bankAccount.cc new file mode 100644 index 0000000..ede21f8 --- /dev/null +++ b/cs162/wk6/friends/bankAccount.cc @@ -0,0 +1,43 @@ +#include "bankAccount.hh" + +#include <iostream> + +bool BankAccount::withdraw(float amount) { + bool canWithdraw = true; + + if (amount <= this->balance) { + this->balance -= amount; + } else { + canWithdraw = false; + } + + return canWithdraw; +} + +float BankAccount::computeInterest(float interestRate) const { + if (this->balance > 0) { + return this->balance * interestRate; + } else { + return 0; + } +} + +std::string BankAccount::greaterBalance(BankAccount &bankAccount) { + if (this->balance > bankAccount.balance) { + return this->accountNumber; + } else { + return bankAccount.accountNumber; + } +} + +void printAccount(const BankAccount &bankAccount) { + std::cout << bankAccount.accountNumber << std::endl; + std::cout << bankAccount.balance << std::endl; +} + +BankAccount combineAccounts(const BankAccount &bankAccount1, + const BankAccount &bankAccount2) { + return BankAccount(std::to_string(std::stoi(bankAccount1.accountNumber) + + std::stoi(bankAccount2.accountNumber)), + bankAccount1.balance + bankAccount2.balance); +} |