-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAccount.cpp
More file actions
99 lines (74 loc) · 1.92 KB
/
Copy pathAccount.cpp
File metadata and controls
99 lines (74 loc) · 1.92 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Created by Jairo Riaño on 13/04/20.
//
#include <sstream>
#include "Account.h"
const double Account::minResidue = 50000;
Account::Account() {
this->number = std::string();
this->customer = NULL;
this->residue = 0;
this->consignments = 0;
this->withdrawals = 0;
}
Account::Account(Customer* customer, const std::string &number, double residue) : number(number), residue(residue) {
setNumber( number );
setCustomer( customer );
setResidue( residue);
this->consignments = 0;
this->withdrawals = 0;
}
void Account::setNumber(const std::string &number) {
Account::number = number;
}
void Account::setCustomer(Customer *customer) {
Account::customer = customer;
}
void Account::setResidue(double residue) {
Account::residue = residue;
}
std::string Account::parseNum(double value) {
std::ostringstream aux;
aux << value;
return aux.str();
}
const std::string &Account::getNumber() const {
return number;
}
double Account::getResidue() const {
return residue;
}
int Account::getConsignments() const {
return consignments;
}
int Account::getWithdrawals() const {
return withdrawals;
}
void Account::consign(double value) {
setResidue( getResidue() + value );
consignments++;
}
bool Account::withDraw(double value) {
if ( value <= getResidue() - Account::minResidue ){
setResidue( getResidue() - value );
withdrawals++;
return true;
}
return false;
}
bool Account::transfer(Account* account, double value) {
if ( withDraw( value) ){
account->consign( value );
return true;
}
return false;
}
std::string Account::toString() {
return "Account[number=" + number +", residue=" + parseNum( residue ) + ", consignments=" +
parseNum( consignments) + ", withdrawals=" + parseNum( withdrawals) +"]\n";
}
Customer* Account::getCustomer() {
return customer;
}
Account::~Account() {
}