Solved: 20 - Classes and Objects
This commit is contained in:
@@ -2,20 +2,23 @@
|
||||
|
||||
namespace oop {
|
||||
|
||||
BankAccount::BankAccount(std::string owner, double balance)
|
||||
BankAccount::BankAccount(std::string owner, const double balance)
|
||||
: owner_(std::move(owner)), balance_(balance) {}
|
||||
|
||||
auto BankAccount::owner() const -> const std::string& { return owner_; }
|
||||
auto BankAccount::balance() const -> double { return balance_; }
|
||||
|
||||
void BankAccount::deposit(double amount) {
|
||||
// TODO: Add amount when positive
|
||||
(void)amount;
|
||||
void BankAccount::deposit(const double amount)
|
||||
{
|
||||
this->balance_ += amount;
|
||||
}
|
||||
|
||||
auto BankAccount::withdraw(double amount) -> bool {
|
||||
// TODO: Return false if insufficient funds, else subtract and return true
|
||||
(void)amount;
|
||||
auto BankAccount::withdraw(const double amount) -> bool
|
||||
{
|
||||
if (this->balance_ >= amount) {
|
||||
this->balance_ -= amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user