-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBanking Management.cpp
More file actions
313 lines (309 loc) · 6.93 KB
/
Copy pathBanking Management.cpp
File metadata and controls
313 lines (309 loc) · 6.93 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include <iostream>
#include <fstream>
#include <iomanip> // for setw() function
using namespace std;
class account
{
int acc_no;
char acc_name[20];
int dep;
char acc_type;
public:
void create_acc();
void display_acc();
void modify_acc();
void deposit_acc(int);
void withdraw_acc(int);
void all_acc(); // function for displaying all the accounts in tabular form
int ret_acc()
{
return acc_no;
}
int ret_dep()
{
return dep;
}
char ret_type()
{
return acc_type;
}
};
void account::create_acc()
{
cout<<" \n Enter the account no: ";
cin>>acc_no;
cout<<" \n Enter the name of the account holder: ";
cin.ignore();
cin.getline(acc_name,20);
cout<<" \n Enter the account type (c/s): ";
cin>>acc_type;
cout<<" \n Enter the amount you want to initially deposit: ";
cin>>dep;
cout<<" \n\n Account Created ";
cout<<endl;
}
void account::display_acc()
{
cout<<" \n Account no: ";
cout<<acc_no;
cout<<" \n Account holder name: ";
cout<<acc_name;
cout<<" \n Account type: ";
cout<<acc_type;
cout<<" \n Balance Amount: ";
cout<<dep;
cout<<endl;
}
void account::modify_acc()
{
cout<<" \n Account no: ";
cout<<acc_no;
cout<<" \n New modified account holder name: ";
cin.ignore();
cin.getline(acc_name,20);
cout<<" \n New modified type of account (c/s): ";
cin>>acc_type;
cout<<" \n New modified balance amount: ";
cin>>dep;
cout<<endl;
}
void account::deposit_acc(int x)
{
dep=dep+x;
cout<<endl;
}
void account::withdraw_acc(int y)
{
dep=dep-y;
cout<<endl;
}
void account::all_acc()
{
cout<<" "<<acc_no<<setw(10)<<" "<<acc_name<<setw(6)<<" "<<acc_type<<setw(15)<<dep<<endl;
}
class bank
{
account a;
ofstream fout;
ifstream fin;
fstream f;
public:
void write();
void output();
void modify();
void delete_single();
void all(); // displaying all accounts in tabular form
void deposit();
void withdraw();
};
void bank::write()
{
fout.open("acc.dat",ios::binary|ios::app);
if(fout)
{
a.create_acc();
fout.write((char*)&a,sizeof(a));
}
fout.close();
if(!fout)
{
cout<<" \n File does not exist ";
}
}
void bank::output()
{
int n,flag=0;
cout<<" \n Enter the account no to be displayed: ";
cin>>n;
fin.open("acc.dat",ios::binary);
while(fin.read((char*)&a,sizeof(a)))
{
if(a.ret_acc()==n)
{
a.display_acc();
flag=1;
}
}
fin.close();
if(flag==0)
{
cout<<" \n Wrong account no ";
}
}
void bank::modify()
{
int n,flag=0;
cout<<" \n Enter the account no to be modified: ";
cin>>n;
f.open("acc.dat",ios::binary|ios::in|ios::out);
while(f.read((char*)&a,sizeof(a)))
{
if(a.ret_acc()==n)
{
a.display_acc();
cout<<" \n Enter the modified details ";
a.modify_acc();
double pos=-1*sizeof(a);
f.seekp(pos,ios::cur);
f.write((char*)&a,sizeof(a));
flag=1;
cout<<" \n Record updated ";
}
}
f.close();
if(flag==0)
{
cout<<" \n Wrong account no ";
}
}
void bank::deposit()
{
int n,flag=0,amt;
cout<<" \n Enter the account no in which money to be deposited: ";
cin>>n;
f.open("acc.dat",ios::binary|ios::in|ios::out);
while(f.read((char*)&a,sizeof(a)))
{
if(a.ret_acc()==n)
{
a.display_acc();
cout<<" \n Enter the amount to be deposited: ";
cin>>amt;
a.deposit_acc(amt);
double pos=-1*sizeof(a);
f.seekp(pos,ios::cur);
f.write((char*)&a,sizeof(a));
flag=1;
cout<<" \n Record updated ";
}
}
f.close();
if(flag==0)
{
cout<<" \n Wrong account no ";
}
}
void bank::withdraw()
{
int n,flag=0,amt;
cout<<" \n Enter the account no in which money to be withdrawn: ";
cin>>n;
f.open("acc.dat",ios::binary|ios::in|ios::out);
while(f.read((char*)&a,sizeof(a)))
{
if(a.ret_acc()==n)
{
a.display_acc();
cout<<" \n Enter the amount to be withdrawn: ";
cin>>amt;
a.withdraw_acc(amt);
cout<<" After withdraw";
a.display_acc();
double pos=-1*sizeof(a);
f.seekp(pos,ios::cur);
f.write((char*)&a,sizeof(a));
flag=1;
cout<<" \n Record updated ";
}
}
f.close();
if(flag==0)
{
cout<<" \n Wrong account no ";
}
}
void bank::all()
{
fin.open("acc.dat",ios::binary);
if(!fin)
{
cout<<" \n File does not exist ";
}
else
{
cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout<<"==========================================================\n";
cout<<" ACC NO. NAME TYPE BALANCE\n";
cout<<"==========================================================\n";
while(fin.read((char*)&a,sizeof(account)))
{
a.all_acc();
}
}
fin.close();
}
void bank::delete_single()
{
int n,flag=0;
cout<<" \n Enter the account no to be deleted: ";
cin>>n;
fout.open("new.dat",ios::binary);
fin.open("acc.dat",ios::binary);
while(fin.read((char*)&a,sizeof(a)))
{
if(a.ret_acc()!=n)
{
fout.write((char*)&a,sizeof(a));
flag=1;
}
}
fout.close();
fin.close();
remove("acc.dat");
rename("new.dat","acc.dat");
if(flag==0)
{
cout<<" \n Wrong account no ";
}
if(flag==1)
{
cout<<" \n Record deleted ";
}
}
int main()
{
bank b;
cout<<"\n\n \t****************";
cout<<" \n\t* BANK * \n";
cout<<" \t* MANAGEMENT * \n";
cout<<" \t* SYSTEM * \n";
cout<<" \t****************"<<endl;
int c;
do
{
cout<<"\n\n\t MENU \n";
cout<<"\n 1. NEW ACCOUNT";
cout<<"\n 2. DEPOSIT AMOUNT";
cout<<"\n 3. WITHDRAW AMOUNT";
cout<<"\n 4. BALANCE ENQUIRY";
cout<<"\n 5. ALL ACCOUNT HOLDER LIST";
cout<<"\n 6. CLOSE AN ACCOUNT";
cout<<"\n 7. MODIFY AN ACCOUNT";
cout<<"\n 8. EXIT";
cout<<"\n Select Your Option (1-8): ";
cin>>c;
cout<<endl;
switch(c)
{
case 1: b.write();
break;
case 2: b.deposit();
break;
case 3: b.withdraw();
break;
case 4: b.output();
break;
case 5: b.all();
break;
case 6: b.delete_single();
break;
case 7: b.modify();
break;
case 8: cout<<" \n\n THANK YOU \n\n";
break;
default: cout<<" \n ENTER VALID CHOICE \n ";
}
cin.ignore();
}while(c!=8);
return 0;
}