-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathManagementBank.cpp
More file actions
99 lines (73 loc) · 2.25 KB
/
Copy pathManagementBank.cpp
File metadata and controls
99 lines (73 loc) · 2.25 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 "ManagementBank.h"
ManagementBank::ManagementBank() {
}
Customer *ManagementBank::findCustomer(std::string idCustomer) {
for( Customer* customer : customers ){
if( customer->getIdCustomer().compare( idCustomer ) == 0 ){
return customer;
}
}
return NULL;
}
bool ManagementBank::addCustomer(std::string idCustomer, std::string firstName, std::string lastName, EGender gender, std::string phone) {
if ( !findCustomer(idCustomer) ){
customers.push_back(new Customer(idCustomer,firstName,lastName,gender,phone));
return true;
}
return false;
}
Account *ManagementBank::findAccount(std::string number) {
for( Account* account : accounts ){
if ( account->getNumber().compare(number) == 0 ){
return account;
}
}
return NULL;
}
bool ManagementBank::addAccount(std::string idCustomer, std::string number, double value) {
Customer* customer = findCustomer( idCustomer);
if ( customer ){
if ( !findAccount( number ) ){
Account* account = new Account(customer,number,value);
accounts.push_back( account );
customer->addAccount( account );
return true;
}
return false;
}
return false;
}
bool ManagementBank::consign(std::string number, double value) {
Account* account = findAccount( number );
if( account ){
account->consign( value );
return true;
}
return false;
}
bool ManagementBank::withDraw(std::string number, double value) {
Account* account = findAccount( number );
if( account ){
return account->withDraw( value );
}
return false;
}
bool ManagementBank::transfer(std::string source, std::string target, double value) {
Account* ctaSource = findAccount(source);
Account* ctaTarget = findAccount(target);
if(ctaSource && ctaTarget){
return ctaSource->transfer( ctaTarget, value );
}
return false;
}
std::vector<Customer *> ManagementBank::getCustomers() {
return std::vector<Customer *>(customers);
}
ManagementBank::~ManagementBank() {
}
std::vector<Account *> ManagementBank::getAccounts() {
return std::vector<Account *>( accounts );
}