-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.cpp
executable file
·164 lines (152 loc) · 4.24 KB
/
Account.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "Account.h"
Account::Account(string fName, string lName, int AccID)
{
insertCheck = false;
firstName = fName;
lastName = lName;
accountNum = AccID;
string fundNames[] = { "Money Market", "Prime Money Market",
"Long-Term Bond", "Short-Term Bond",
"500 Index Fund", "Capital Value Fund",
"Growth Equity Fund", "Growth Index Fund",
"Value Fund", "Value Stock Index" };
for (int i = 0; i < 10;i++)
{
FundArray[i].setFundName(fundNames[i]);
FundArray[i].setBalance(0);
}
}
string Account::getFirstName()const
{
return firstName;
}
string Account::getLastName()const
{
return lastName;
}
string Account::getFundName(int FundID)const
{
return FundArray[FundID].getFundName();
}
int Account::getFundBalance(int FundID)const
{
return FundArray[FundID].getBalance();
}
bool Account::getIncertCheck()const
{
return insertCheck;
}
int Account::getAccountNum()const
{
return accountNum;
}
void Account::setFirstName(string Name)
{
firstName = Name;
}
void Account::setLastName(string Name)
{
lastName = Name;
}
bool Account::setAmountNum(int accNum)
{
accountNum = accNum;
return true;
}
void Account::addFunds(int addMoney, int fid)
{
FundArray[fid].addFunds(addMoney);
}
bool Account::subFunds(int subMoney, int fid)
{
if (FundArray[fid].enoughFundsWithdrawl(subMoney))
{
FundArray[fid].subFunds(subMoney);
return true;
}
if (fid >= 0 && fid <= 3)
{
if (fid == 0)
{
if (FundArray[fid].getBalance() + FundArray[1].getBalance() >= subMoney)
{
int leftOverBanlance = subMoney - FundArray[fid].getBalance();
FundArray[fid].subFunds(subMoney-leftOverBanlance);
FundArray[1].subFunds(leftOverBanlance);
Transactions* first = new Transactions('W', accountNum * 10 + fid, subMoney - leftOverBanlance);
Transactions* secound = new Transactions('W', accountNum * 10 + (1), leftOverBanlance);
FundArray[fid].addTransaction(*first);
FundArray[1].addTransaction(*secound);
insertCheck = true;
return true;
}
}
else if (fid == 1)
{
if (FundArray[fid].getBalance() + FundArray[0].getBalance() >= subMoney)
{
int leftOverBanlance = subMoney - FundArray[fid].getBalance();
FundArray[fid].subFunds(subMoney - leftOverBanlance);
FundArray[0].subFunds(leftOverBanlance);
Transactions* first = new Transactions('W', accountNum * 10 + fid, subMoney - leftOverBanlance);
Transactions* secound = new Transactions('W', accountNum * 10 + (0), leftOverBanlance);
FundArray[fid].addTransaction(*first);
FundArray[0].addTransaction(*secound);
insertCheck = true;
return true;
}
}
else if (fid == 2)
{
if (FundArray[fid].getBalance() + FundArray[fid + 1].getBalance() >= subMoney)
{
int leftOverBanlance = subMoney - FundArray[fid].getBalance();
FundArray[fid].subFunds(subMoney - leftOverBanlance);
FundArray[3].subFunds(leftOverBanlance);
Transactions* first = new Transactions('W', accountNum * 10 + fid, subMoney - leftOverBanlance);
Transactions* secound = new Transactions('W', accountNum * 10 + (3), leftOverBanlance);
FundArray[fid].addTransaction(*first);
FundArray[3].addTransaction(*secound);
insertCheck = true;
return true;
}
}
else if (fid == 3)
{
if (FundArray[fid].getBalance() + FundArray[fid - 1].getBalance() >= subMoney)
{
int leftOverBanlance = subMoney - FundArray[fid].getBalance();
FundArray[fid].subFunds(subMoney - leftOverBanlance);
FundArray[2].subFunds(leftOverBanlance);
Transactions* first = new Transactions('W', accountNum * 10 + fid, subMoney - leftOverBanlance);
Transactions* secound = new Transactions('W', accountNum * 10 + (2), leftOverBanlance);
FundArray[fid].addTransaction(*first);
FundArray[2].addTransaction(*secound);
insertCheck = true;
return true;
}
}
}
else
{
return false;
}
}
void Account::printHistoryAll()
{
for (int i = 0; i < 10; i++)
{
FundArray[i].printHisotryFund();
}
}
void Account::printFundHistory(int fID)
{
FundArray[fID].printHisotryFund();
}
void Account::conductedTransaction(Transactions tran, int fID)
{
FundArray[fID].addTransaction(tran);
}
Account::~Account()
{
}