-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.cpp
More file actions
134 lines (88 loc) · 2.47 KB
/
Bank.cpp
File metadata and controls
134 lines (88 loc) · 2.47 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "Bank.h"
#include "Account.h"
#include <time.h>
#include <ostream>
Bank Bank::m_bank;
Bank::Bank() {
//DO NOTHING
}
Bank::~Bank() {
//Delete all of the accounts
for (vector<Account *>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++){
delete *it;
}
m_accounts.clear();
}
Account *Bank::createNewAccount(int type, int date, int period, float PrecentOnDeposite){
Account_Type aType;
Period aPeriod;
if (type == 0)
aType = TWOYEARS;
else if (type == 1)
aType = FAMILY;
else
aType = STOCKEXCHANGE;
if (period == 3)
aPeriod = THREE;
else if (period == 7)
aPeriod = SEVEN;
else
aPeriod = TEN;
Account *acc = new Account(aType, date, aPeriod, PrecentOnDeposite, m_accounts.size());
this->Attach(acc);
return acc;
}
void Bank::Attach( Account* acc)
{
m_accounts.push_back(acc);
}
void Bank::Detach( Account* acc)
{
unsigned int i = 0;
for (i = 0; i < m_accounts.size(); i++)
if (m_accounts[i] == acc) break;
m_accounts.erase(m_accounts.begin() + i);
}
void Bank::deposit(int id, int amount){
if (id >= 0 && id < m_accounts.size())
m_accounts[id]->Update(DEPOSIT, amount, "");
}
void Bank::withdraw(int id, int amount){
if (id >= 0 && id < m_accounts.size())
m_accounts[id]->Update(WITHDRAWAL, amount, "");
}
ostream &operator<< (ostream &os, Bank &bank){
for (vector<Account *>::iterator it = bank.m_accounts.begin(); it != bank.m_accounts.end(); it++){
os << **it;
}
return os;
}
/** Ovserver notify methods **/
/* Invest in stock exchange only for accounts with openng time not bigger the 5 years ago
and that saving period is TEN */
void Bank::InvestInStockExchange(int amount){
time_t rawtime;
time (&rawtime);
struct tm * timeinfo;
timeinfo = localtime(&rawtime);
int year = timeinfo->tm_year + 1900;
for (vector<Account *>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++){
if ((*it)->getDate() > year - 5 && (*it)->getPeriod() == TEN && (*it)->getType() == STOCKEXCHANGE){
(*it)->Update(DEPOSITSTOCK, amount, "");
}
}
}
/* Give 500 shekels bonus to family accounts */
void Bank::GiveFamilyBonus(){
for (vector<Account *>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++){
if ((*it)->getType() == FAMILY){
(*it)->Update(DEPOSIT, 500, "");
}
}
}
/* Notify all accounts to come to bank */
void Bank::Notify(){
for (vector<Account *>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++){
(*it)->Update(NOTIFY, 0, "Come to the bank please");
}
}