From e4bc857f1f7edf677c3ffec8021db57043db350d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 26 Jun 2020 15:01:47 +0300 Subject: Started working on a C++ basic bank account project. You can create an account, deposit and withdraw money from it for now. --- CPP/BABS/BankAccount.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 CPP/BABS/BankAccount.cpp (limited to 'CPP/BABS/BankAccount.cpp') diff --git a/CPP/BABS/BankAccount.cpp b/CPP/BABS/BankAccount.cpp new file mode 100644 index 0000000..180f56c --- /dev/null +++ b/CPP/BABS/BankAccount.cpp @@ -0,0 +1,43 @@ +#include + +#include "BankAccount.h" + +int currId = 0; + +BankAccount::BankAccount() { + id = currId++; + balance = 0; +} + +BankAccount::BankAccount(int initialDeposit) { + id = currId++; + balance = initialDeposit; +} + +int BankAccount::getId() { + return id; +} + +int BankAccount::getBalance() { + return balance; +} + +void BankAccount::deposit(int amount) { + balance += amount; +} + +int BankAccount::withdraw(int amount) { + if (amount > balance) { + return -1; + } + balance -= amount; + return amount; +} + +std::string BankAccount::toString() { + return "ID: " + std::to_string(id) + " Balance: " + std::to_string(balance); +} + +void BankAccount::close() { + closed = true; +} \ No newline at end of file -- cgit v1.2.3