You are on page 1of 5

h a n g e Pro h a n g e Pro

XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
1 //***************************************************************
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
2 // HEADER FILE USED IN PROJECT
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a
3 //****************************************************************
4
5 #include<iostream>
6 # include<cstdlib>
7 #include<fstream>
8 #include<cctype>
9 #include<iomanip>
10 using namespace std;
11
12 //***************************************************************
13 // CLASS USED IN PROJECT
14 //****************************************************************
15
16 class account
17 {
18 int acno;
19 char name[50];
20 int deposit;
21 char type;
22 public:
23 void create_account(); //function to get data from user
24 void show_account() const; //function to show data on screen
25 void modify(); //function to add new data
26 void dep(int); //function to accept amount and add to balance amount
27 void draw(int); //function to accept amount and subtract from balance amount
28 void report() const; //function to show data in tabular format
29 int retacno() const; //function to return account number
30 int retdeposit() const; //function to return balance amount
31 char rettype() const; //function to return type of account
32 }; //class ends here
33
34 void account::create_account()
35 {
36 cout<<"\nEnter The account No. : ";
37 cin>>acno;
38 cout<<"\n\nEnter The Name of The account Holder : ";
39 cin.ignore();
40 cin.getline(name,50);
41 cout<<"\nEnter Type of The account (C/S) : ";
42 cin>>type;
43 type=toupper(type);
44 cout<<"\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
45 cin>>deposit;
46 cout<<"\n\n\nAccount Created..";
47 }
48
49 void account::show_account() const
50 {
51 cout<<"\nAccount No. : "<<acno;
52 cout<<"\nAccount Holder Name : ";
53 cout<<name;
54 cout<<"\nType of Account : "<<type;
55 cout<<"\nBalance amount : "<<deposit;
56 }
57
58
59 void account::modify()
60 {
61 cout<<"\nAccount No. : "<<acno;
62 cout<<"\nModify Account Holder Name : ";
63 cin.ignore();
64 cin.getline(name,50);
65 cout<<"\nModify Type of Account : ";
66 cin>>type;
67 type=toupper(type);
68 cout<<"\nModify Balance amount : ";
69 cin>>deposit;
70 }
71
72
73 void account::dep(int x)
74 {
75 deposit+=x;
76 }
77
78 void account::draw(int x)
79 {
80 deposit-=x;
81 }
82
83 void account::report() const
84 {
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
85 cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl;
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
86 }
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a
87
88 int account::retacno() const
89 {
90 return acno;
91 }
92
93 int account::retdeposit() const
94 {
95 return deposit;
96 }
97
98 char account::rettype() const
99 {
100 return type;
101 }
102
103
104 //***************************************************************
105 // function declaration
106 //****************************************************************
107 void write_account(); //function to write record in binary file
108 void display_sp(int); //function to display account details given by user
109 void modify_account(int); //function to modify record of file
110 void delete_account(int); //function to delete record of file
111 void display_all(); //function to display all account details
112 void deposit_withdraw(int, int); // function to desposit/withdraw amount for given account
113 void intro(); //introductory screen function
114
115 //***************************************************************
116 // THE MAIN FUNCTION OF PROGRAM
117 //****************************************************************
118
119 int main()
120 {
121 char ch;
122 int num;
123 intro();
124 do
125 {
126
127 cout<<"\n\n\n\tMAIN MENU";
128 cout<<"\n\n\t01. NEW ACCOUNT";
129 cout<<"\n\n\t02. DEPOSIT AMOUNT";
130 cout<<"\n\n\t03. WITHDRAW AMOUNT";
131 cout<<"\n\n\t04. BALANCE ENQUIRY";
132 cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST";
133 cout<<"\n\n\t06. CLOSE AN ACCOUNT";
134 cout<<"\n\n\t07. MODIFY AN ACCOUNT";
135 cout<<"\n\n\t08. EXIT";
136 cout<<"\n\n\tSelect Your Option (1-8) ";
137 cin>>ch;
138 system("cls");
139 switch(ch)
140 {
141 case '1':
142 write_account();
143 break;
144 case '2':
145 cout<<"\n\n\tEnter The account No. : "; cin>>num;
146 deposit_withdraw(num, 1);
147 break;
148 case '3':
149 cout<<"\n\n\tEnter The account No. : "; cin>>num;
150 deposit_withdraw(num, 2);
151 break;
152 case '4':
153 cout<<"\n\n\tEnter The account No. : "; cin>>num;
154 display_sp(num);
155 break;
156 case '5':
157 display_all();
158 break;
159 case '6':
160 cout<<"\n\n\tEnter The account No. : "; cin>>num;
161 delete_account(num);
162 break;
163 case '7':
164 cout<<"\n\n\tEnter The account No. : "; cin>>num;
165 modify_account(num);
166 break;
167 case '8':
168 cout<<"\n\n\tThanks for using bank managemnt system";
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
169 break;
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
170 default :cout<<"\a";
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a
171 }
172 cin.ignore();
173 cin.get();
174 }while(ch!='8');
175 return 0;
176 }
177
178
179 //***************************************************************
180 // function to write in file
181 //****************************************************************
182
183 void write_account()
184 {
185 account ac;
186 ofstream outFile;
187 outFile.open("account.dat",ios::binary|ios::app);
188 ac.create_account();
189 outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
190 outFile.close();
191 }
192
193 //***************************************************************
194 // function to read specific record from file
195 //****************************************************************
196
197 void display_sp(int n)
198 {
199 account ac;
200 bool flag=false;
201 ifstream inFile;
202 inFile.open("account.dat",ios::binary);
203 if(!inFile)
204 {
205 cout<<"File could not be open !! Press any Key...";
206 return;
207 }
208 cout<<"\nBALANCE DETAILS\n";
209 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
210 {
211 if(ac.retacno()==n)
212 {
213 ac.show_account();
214 flag=true;
215 }
216 }
217 inFile.close();
218 if(flag==false)
219 cout<<"\n\nAccount number does not exist";
220 }
221
222
223 //***************************************************************
224 // function to modify record of file
225 //****************************************************************
226
227 void modify_account(int n)
228 {
229 bool found=false;
230 account ac;
231 fstream File;
232 File.open("account.dat",ios::binary|ios::in|ios::out);
233 if(!File)
234 {
235 cout<<"File could not be open !! Press any Key...";
236 return;
237 }
238 while(!File.eof() && found==false)
239 {
240 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
241 if(ac.retacno()==n)
242 {
243 ac.show_account();
244 cout<<"\n\nEnter The New Details of account"<<endl;
245 ac.modify();
246 int pos=(-1)*static_cast<int>(sizeof(account));
247 File.seekp(pos,ios::cur);
248 File.write(reinterpret_cast<char *> (&ac), sizeof(account));
249 cout<<"\n\n\t Record Updated";
250 found=true;
251 }
252 }
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
253 File.close();
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
254 if(found==false)
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a
255 cout<<"\n\n Record Not Found ";
256 }
257
258 //***************************************************************
259 // function to delete record of file
260 //****************************************************************
261
262
263 void delete_account(int n)
264 {
265 account ac;
266 ifstream inFile;
267 ofstream outFile;
268 inFile.open("account.dat",ios::binary);
269 if(!inFile)
270 {
271 cout<<"File could not be open !! Press any Key...";
272 return;
273 }
274 outFile.open("Temp.dat",ios::binary);
275 inFile.seekg(0,ios::beg);
276 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
277 {
278 if(ac.retacno()!=n)
279 {
280 outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
281 }
282 }
283 inFile.close();
284 outFile.close();
285 remove("account.dat");
286 rename("Temp.dat","account.dat");
287 cout<<"\n\n\tRecord Deleted ..";
288 }
289
290 //***************************************************************
291 // function to display all accounts deposit list
292 //****************************************************************
293
294 void display_all()
295 {
296 account ac;
297 ifstream inFile;
298 inFile.open("account.dat",ios::binary);
299 if(!inFile)
300 {
301 cout<<"File could not be open !! Press any Key...";
302 return;
303 }
304 cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
305 cout<<"====================================================\n";
306 cout<<"A/c no. NAME Type Balance\n";
307 cout<<"====================================================\n";
308 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
309 {
310 ac.report();
311 }
312 inFile.close();
313 }
314
315 //***************************************************************
316 // function to deposit and withdraw amounts
317 //****************************************************************
318
319 void deposit_withdraw(int n, int option)
320 {
321 int amt;
322 bool found=false;
323 account ac;
324 fstream File;
325 File.open("account.dat", ios::binary|ios::in|ios::out);
326 if(!File)
327 {
328 cout<<"File could not be open !! Press any Key...";
329 return;
330 }
331 while(!File.eof() && found==false)
332 {
333 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
334 if(ac.retacno()==n)
335 {
336 ac.show_account();
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
337 if(option==1)
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
338 {
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a
339 cout<<"\n\n\tTO DEPOSITE AMOUNT ";
340 cout<<"\n\nEnter The amount to be deposited";
341 cin>>amt;
342 ac.dep(amt);
343 }
344 if(option==2)
345 {
346 cout<<"\n\n\tTO WITHDRAW AMOUNT ";
347 cout<<"\n\nEnter The amount to be withdraw";
348 cin>>amt;
349 int bal=ac.retdeposit()-amt;
350 if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C'))
351 cout<<"Insufficience balance";
352 else
353 ac.draw(amt);
354 }
355 int pos=(-1)*static_cast<int>(sizeof(ac));
356 File.seekp(pos,ios::cur);
357 File.write(reinterpret_cast<char *> (&ac), sizeof(account));
358 cout<<"\n\n\t Record Updated";
359 found=true;
360 }
361 }
362 File.close();
363 if(found==false)
364 cout<<"\n\n Record Not Found ";
365 }
366
367
368 //***************************************************************
369 // INTRODUCTION FUNCTION
370 //****************************************************************
371
372 void intro()
373 {
374 cout<<"\n\n\n\t BANK";
375 cout<<"\n\n\tMANAGEMENT";
376 cout<<"\n\n\t SYSTEM";
377 cout<<"\n\n\n\nMADE BY : your name";
378 cout<<"\n\nSCHOOL : your school name";
379 cin.get();
380 }
381
382 //***************************************************************
383 // END OF PROJECT
384 //***************************************************************
385

You might also like