Solved: 20 - Classes and Objects

This commit is contained in:
2026-08-15 17:43:30 +03:00
parent 8b82257ed6
commit 564cc1b765
3 changed files with 14 additions and 9 deletions
@@ -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;
}