-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.cpp
More file actions
48 lines (40 loc) · 975 Bytes
/
account.cpp
File metadata and controls
48 lines (40 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// account.cpp
// Test Product
//
// Created by David Brown on 05/06/2017.
// Copyright © 2017 David Brown. All rights reserved.
//
#include "account.hpp"
Account::Account()
{
stats = Statistics::Instance();
settings = Settings::Instance();
balance = 0;
id = Settings::getId();
reg = Register::Instance();
}
int Account::getBalance()
{
return balance;
}
// Use transferTo() in preference to credit()as credit() doesn't upate our balance
bool Account::transferTo(Account *recipient, int amount, Account *creditor)
{
if (amount > balance) {
std::cout << "Account " << id << ": insufficient funds (" << balance << " available, " << amount << " to pay)\n";
return false;
} else {
recipient->credit(amount, creditor);
balance -= amount;
return true;
}
}
void Account::credit(int amount, Account *creditor)
{
balance += amount;
}
int Account::getId() const
{
return id;
}