-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.cpp
140 lines (127 loc) · 3.46 KB
/
bank.cpp
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
133
134
135
136
137
138
139
140
#include "bank.h"
#include <time.h>
#include <cstdlib>
int Bank::ourCount = 0;
Bank::Bank(const string &name)
: myCurrentDate(new Date()),
myNumber(ourCount),
myName(name)
{
ourCount++;
}
Bank::Bank(Date *dd, const string& name)
: myCurrentDate(dd),
myNumber(ourCount),
myName(name)
{
ourCount++;
}
void Bank::GetIDs()
{
cout << "***********************************************" << endl;
cout << "* Bank Accounts (" << myNumber << ") " << myName << endl;
cout << "* ";
GetDate();
cout << "*" << endl;
for(int i = 0; i < Accounts.size(); i++)
cout << "* " << i+1 << " " << *Accounts[i] << endl;
cout << "*\n***********************************************" << endl;
}
void Bank::GetAccounts()
{
cout << "***********************************************" << endl;
cout << "* Bank Accounts (" << myNumber << ") " << myName << endl;
cout << "* ";
GetDate();
cout << "*" << endl;
for(int i = 0; i < Accounts.size(); i++)
cout << "* " << i+1 << " " << Accounts[i]->DeepString() << endl;
cout << "*\n***********************************************" << endl;
}
void Bank::Deposit(int ID, BigInteger cash)
{
bool found = false;
for(int i = 0; i < Accounts.size(); i++)
{
if(Accounts[i]->GetID() == ID)
{
Accounts[i]->Deposite(cash, myCurrentDate);
found = true;
}
}
}
bool Bank::WithDraw(int ID, BigInteger cash)
{
bool done = false;
bool found = false;
for(int i = 0; i < Accounts.size(); i++)
{
if(Accounts[i]->GetID() == ID)
{
done = Accounts[i]->WithDraw(cash, myCurrentDate);
found = true;
}
}
}
void Bank::Sortition()
{
vector<int> points;
srand(time(NULL));
for(int i = 0; i < Accounts.size(); i++)
{
if(AccountTypes[i] == GHARZOL_HASANE)
{
int tmp = Accounts[i]->GetBalance();
for(int j = 0; j < tmp; j++)
points.push_back(Accounts[i]->GetID());
}
}
if(!points.empty())
{
int winner = rand() % points.size();
int winnerID = points[winner];
cout << "Winner is : " << winnerID << endl;
for(int i = 0; i < Accounts.size(); i++)
{
if(Accounts[i]->GetID() == winnerID)
{
Accounts[i]->Deposite(111111, myCurrentDate);
}
}
}
}
Date * Bank::GetDate(DateType t) const
{
if(t == GREGORIAN)
cout << myCurrentDate->GregorianToString() << endl;
if(t == JALALI)
cout << myCurrentDate->JalaliToString() << endl;
}
void Bank::SetDate(Date *dd)
{
myCurrentDate = dd;
for(int i = 0; i < Accounts.size(); i++)
Accounts[i]->Benefit(dd);
}
void Bank::CreateAccount(int ID, BigInteger cash, AccountType type, const string& name)
{
switch(type)
{
case SHORT_TERM:
Accounts.push_back(new ShortTerm(ID, cash, myCurrentDate, name));
AccountTypes.push_back(SHORT_TERM);
break;
case LONG_TERM:
Accounts.push_back(new LongTerm(ID, cash, myCurrentDate, name));
AccountTypes.push_back(LONG_TERM);
break;
case CURRENT:
Accounts.push_back(new Current(ID, cash, myCurrentDate, name));
AccountTypes.push_back(CURRENT);
break;
case GHARZOL_HASANE:
Accounts.push_back(new GharzolHasane(ID, cash, myCurrentDate, name));
AccountTypes.push_back(GHARZOL_HASANE);
break;
}
}