/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-101-008/main.cpp
35 строк
825 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class BankAccount { public: explicit BankAccount(double initial_balance) : balance_(initial_balance) { if (initial_balance < 0.0) { throw std::invalid_argument("Initial balance cannot be negative"); } } void deposit(double amount) { if (amount <= 0.0) { throw std::invalid_argument("Deposit amount must be positive"); } balance_ += amount; } void withdraw(double amount) { if (amount <= 0.0) { throw std::invalid_argument("Withdrawal amount must be positive"); } if (amount > balance_) { throw std::runtime_error("Insufficient funds"); } balance_ -= amount; } double get_balance() const { return balance_; } private: double balance_; };