code right or

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
Is this code right or am I missing something ?
Savang saV nterest(annuallnterestRate);
(to antsetBalance(intialalance):
1Sop
Run Detug
MSae
men op
9include dostrean
include cfstrean
3 includecstring
4 using nanespace std;
class Account(
int id;
double balance;
publies
r
20
Account ()(
id-
balance =e.e;
21
12
14
Account (int newID, double initialBalance){
id- newlD;
balance-initial8alance;
15
16
17
18
29
20
21
veid setI0(int newID){
id newID;
void settalance(double initialBalance){
balance initialalance,
23
24
25
int getID()
return id;
26
27
28
29
double getsalance(){
return balance;
30
31
void withdraw(double amount){
balance - balance- ount;
32
33
34
35
void deposit(double anount){
balance balance mount,
36
37
38
virtual void closetonth()-e
39
virtual string accountstring()-
41
42
43 );
44 elass Savings:publie Account{
double interest;
double minbalance;
public:
Savings()
46
47
48
49
se
void eloselonth(){
double pre- getsalance();
52
53
double newdalance- pre ((pre (interest/100.0))/12.0):
54
55
setBalance(newBalance);
56
string accountstring()
57
+ to_string(getID()) has balance of S"ito_string(getsalance());
59
return "SavingE account
61
void setInterest(double interest){
this-interest-interest;
62
63
64
void setMintalance(double minlalance)(
this-mintalance minsalance;
65
66
69- class Checking public Account(
double mintalance;
double monthlyree;
71
72 public:
73
Checking(){
74
75
void closelonth()
double nelalance getsalance()
setalance(newalance);
76
77
78
79
monthlyfee,
string accountstring()
81-
return "Checking account + to string(getID()) +" has balance of $"-to_string(gettalance());
82
83
84
85
void setMonthlyFee(double monthlyFee){
this-nonthlyfee nonthlyfee;
86
87
void setMinlalance(double minialance){
this-minalance = minsalance;
88
89
91
92 );
93
94 int nainO{
95
Accountaccounts = new Account [10];
ifstrean infile;
infile.open("bank2.txt");
1n länfile )
cerr « "File cannont be opened" <« endl;
else
cout e "File Opened"endl;
string operationType;
int tetalaccount
96
97
98
99
100
101
102
103
while(infileoperationType)
104
105
106
107
if(operationType "Savings"H
int id;
double initialBalance,minimunbalance, annualInterestRate;
infile > id» initialBalance
Savings "savingAccount
savingiccount-setInterest(annualinterestRate);
savingaccount-setMinbalance(ninimunalance);
accounts (totalAccount) savingaccount:
accounts[totalAccount]-setID(id);
accounts(totalAccount]-setBalance(initialBalance);
tetalAccount-
cout "Saving account nunber "cctotalAccount « created"<endl;
cout"with an initial balance of saccounts[totalAccount-1]-getBalance()cendi;
108
»
new Savings();
minimunsalance » 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, monthlyfees;
infile > id» initial8alance inimunalance >> 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 nunber "cctotalAccount «* created"<cendl;
cout"with an initial balance of S"accounts(totalAccount-1]-gettalance()cendl;
126
127
128
129
130
131
132
133
Transcribed Image Text:Savang saV nterest(annuallnterestRate); (to antsetBalance(intialalance): 1Sop Run Detug MSae men op 9include dostrean include cfstrean 3 includecstring 4 using nanespace std; class Account( int id; double balance; publies r 20 Account ()( id- balance =e.e; 21 12 14 Account (int newID, double initialBalance){ id- newlD; balance-initial8alance; 15 16 17 18 29 20 21 veid setI0(int newID){ id newID; void settalance(double initialBalance){ balance initialalance, 23 24 25 int getID() return id; 26 27 28 29 double getsalance(){ return balance; 30 31 void withdraw(double amount){ balance - balance- ount; 32 33 34 35 void deposit(double anount){ balance balance mount, 36 37 38 virtual void closetonth()-e 39 virtual string accountstring()- 41 42 43 ); 44 elass Savings:publie Account{ double interest; double minbalance; public: Savings() 46 47 48 49 se void eloselonth(){ double pre- getsalance(); 52 53 double newdalance- pre ((pre (interest/100.0))/12.0): 54 55 setBalance(newBalance); 56 string accountstring() 57 + to_string(getID()) has balance of S"ito_string(getsalance()); 59 return "SavingE account 61 void setInterest(double interest){ this-interest-interest; 62 63 64 void setMintalance(double minlalance)( this-mintalance minsalance; 65 66 69- class Checking public Account( double mintalance; double monthlyree; 71 72 public: 73 Checking(){ 74 75 void closelonth() double nelalance getsalance() setalance(newalance); 76 77 78 79 monthlyfee, string accountstring() 81- return "Checking account + to string(getID()) +" has balance of $"-to_string(gettalance()); 82 83 84 85 void setMonthlyFee(double monthlyFee){ this-nonthlyfee nonthlyfee; 86 87 void setMinlalance(double minialance){ this-minalance = minsalance; 88 89 91 92 ); 93 94 int nainO{ 95 Accountaccounts = new Account [10]; ifstrean infile; infile.open("bank2.txt"); 1n länfile ) cerr « "File cannont be opened" <« endl; else cout e "File Opened"endl; string operationType; int tetalaccount 96 97 98 99 100 101 102 103 while(infileoperationType) 104 105 106 107 if(operationType "Savings"H int id; double initialBalance,minimunbalance, annualInterestRate; infile > id» initialBalance Savings "savingAccount savingiccount-setInterest(annualinterestRate); savingaccount-setMinbalance(ninimunalance); accounts (totalAccount) savingaccount: accounts[totalAccount]-setID(id); accounts(totalAccount]-setBalance(initialBalance); tetalAccount- cout "Saving account nunber "cctotalAccount « created"<endl; cout"with an initial balance of saccounts[totalAccount-1]-getBalance()cendi; 108 » new Savings(); minimunsalance » 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, monthlyfees; infile > id» initial8alance inimunalance >> 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 nunber "cctotalAccount «* created"<cendl; cout"with an initial balance of S"accounts(totalAccount-1]-gettalance()cendl; 126 127 128 129 130 131 132 133
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
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
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education