This does not handle the end of month processing correctly. The monthly fee should only be deducted if the balance is below the minimum. Similarly, the interest should only be added if the balance is above the minimum. What does this mean and below is my code and this is a c++ assignment not a Java problem
Transcribed Image Text: (to an setBalance(initialalance);
MSa
Run Detg
1Skop
hre
ba
Minclude ciostream
mn op te
VinCiude cfstrean
3 includecstring
4 using namespace std;
class Account{
int id;
double balance
publies
20
Account (){
id-
balance =e.e;
11
12
10
14
15
Account (int newID, double initialBalance){
id newlD;
balance-initialBalance;
16
17
18
19
20
21
veid setID(int newID){
id newID;
void settalance(double initialBalance){
balance initialalance;
23
24
int getID()
return id;
25
26
27
28
29
deuble getsalance(){
return balance;
30
31
32
veid withdraw(double amount){
balance balance amount;
33
34
35
void deposit(double amount){
balance balance mount:
36
37
38
virtual void closetonth()-e
39
virtual string accountstring()-
41
42
43 );
44 elass Savings:public Account(
double interest;
double minbalance;
public:
Savings()
46
47
48
49
void eloselonth(){
double pre- getalance();
51
52
53
double newialance - pre ((pre (interest/100.0))/12.0);
54
55
setBalance(newalance);
56
string accountstring()
57
59
return "Saving account + to_string(getID()) has balance of S"ito_string(getsalance());
61
62
63
void setInterest(double interest){
this-interest-interest;
void settintalance(double minBalance){
this-mintalance minsalance;
65
66
68 );
69 - class Checking public Account(
double minialance;
double monthlyFee;
71
72 public:
73
Checking(){
74
75
void closehonth()
double nelalance getlalance()
settalance(newalance);
76
77
78
monthlyfee;
string accountstring()
81
return "Checking account+ to_string(getID()) +* has balance of s"-to_string(getBalance());
82
83
84
void setMonthlyFee(double monthlyFee){
this- nonthlyfee nonthlyfee;
85
86
87
88
void setkinlalance(double minlalance){
this-minalance = minsalance;
89
91
92 ):
93
94- int nainO{
95
Account accounts = new Account [10];
ifstrean infile;
infile.open("bank2.txt"):
if( infile )
cerr « "File cannont be opened" <« endl;
else
cout e "File Opened"<cendl;
string operationType;
int totalAccount-e;
while(infileoperationType)
96
97
98
99
100
101
102
103
104
105
106
107
if(operationtype "Savings"H
int id;
double initialBalance,minimundalance, annualInterestRate;
infile » id > initialBalance
Savings "savingAccount- new Savings();
savingkccount-setInterest(annualInterestRate);
savingaccount-setMinbalance(minimunalance);
accounts(totalAccount] = savingaccount;
accounts[totalAccount]-setID(id);
accounts(totalAccount]-setBalance(initialBalance);
tetalAccount;
cout ce"Saving account nunber "cctotalAccount created"<endl;
cout"with an initial balance of saccounts[totalAccount-1]-getBalance()cendi;
108
> ninimunsalance> annualInterestRate;
109
11e
111
112
113
114
115
116
117
118
119
12e
121
122
123
124
125
else if(operationType "Checking )
int id;
double initialBalance,minimunbalance, nonthlyFees;
infile » id > initialBalance >> ninimunsalance > monthlyfees;
Checking "checkingAccount new Checking():
checkingAccount-setMonthlyFee(monthlyFees);
checkingiccount-setkinBalance(mininunBalance);
accounts[totalAccount]- checkingAccount;
accounts(totalAccount)-setiD(id);
accounts[totalAccount]setBalance(initialBalance);
tetalAccount
cout "Checking account number "cctotalAccount « created"<cendl;
cout"with an initial balance of S"accounts[totalAccount-1]-getBalance()cendl;
126
127
128
129
130
131
132
133
Transcribed Image Text: coutewith an initial balance of S"caccounts[totalAccount-1]-getBalance()<cendl;
133
134
135
else if (operationType "Deposit"){
int id;
double amount;
int pos;
bool isFound-=false;
infile >> id > anount;
for(int i-e;i totalAccount;i++){
if (accounts[i]-getID()--id){
136
137
138
139
148
141
142
143
isFound-true;
accounts [i]->deposit(amount);
pos-i;
144
145
146
147
148
if(lisFound){
cout"Invalid Account Number - "<cidccendl;
149
150
151
152
153
elsef
cout cc"Deposited $"<camountce" into account "<cidccendl;
cout<<"current balance is $"<caccounts[pos]-getBalance()<<endl;
154
155
156
else if (operationType == "kithdraw"){
int id;
double amount;
int pos;
infile >> id >> anount;
bool isFound-false;
for(int i-e;itotalAccount;i+){
if (accounts[i]-getID()--id){
157
158
159
160
161
162
163
164
165
isFound-true;
accounts (i]-withdraw(amount);
pos i;
166
167
168
169
178
171
ir(lisFound){
coutce"Invalid Account Number - "ccidccendl;
172
173
elsef
cout ccwithdraw $"ccamount c" from account recidccendl;
coute"current balance is S"caccounts[pos]-getBalance()< cendl;
174
176
177
else if (operationType "Balance"){
int id;
infile >» id;
int pos;
178
179
180
181
bool isFound-false;
for (int i-e;ictotalAccount;i){
if (accounts[i]->getID()=-id){
isFound true;
182
184
185
cout"Current balance in account "ccid e" is S"caccounts[i] getBalance()<cendl;
186
pos i;
187
188
189
ir(lisFound){
coutce"Invalid Account Number
190
191
*c«idccendl;
192
193
194
else if (operationType = "Close"){
cout"End of nonth processing complete"ccendl;
for(int i-e;itotalAccount;i+){
accounts[i]->closeMonth();
195
196
197
198
199
else if (operationType "Report"){
for (int i-e;itotalAccount;i+){
cout « accounts[i]->accountString() « endl;
200
201
202
203
204
elsef
coute"Unrecognised command
string dunnyline;
getline(infile, dumnyline);
205
"ccoperationTypeccendl;
208
afile.close();
213
Input
Wan t
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step 1 Rule Of Three in C++
VIEW
Step 2A coding example follows:
VIEW
Step by step
Solved in 2 steps