aboutsummaryrefslogtreecommitdiff
path: root/CPP/BABS/BankAccount.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-06-26 15:01:47 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-06-26 15:01:47 +0300
commite4bc857f1f7edf677c3ffec8021db57043db350d (patch)
treeff2caab04d41e5dc8288a3deeb4b6553e5356af9 /CPP/BABS/BankAccount.cpp
parent55571ba49d08581ee9d52b653cb84a37d81dd151 (diff)
downloadSelf-learning-e4bc857f1f7edf677c3ffec8021db57043db350d.tar
Self-learning-e4bc857f1f7edf677c3ffec8021db57043db350d.tar.gz
Self-learning-e4bc857f1f7edf677c3ffec8021db57043db350d.zip
Started working on a C++ basic bank account project. You can create an account, deposit and withdraw money from it for now.
Diffstat (limited to 'CPP/BABS/BankAccount.cpp')
-rw-r--r--CPP/BABS/BankAccount.cpp43
1 files changed, 43 insertions, 0 deletions
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 <string>
+
+#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