You are on page 1of 10

SOURCE CODE:

1 ////////////////////////////////////////////////////////////////// ?

2 // HEADER FILE USED IN PROJECT


3 //////////////////////////////////////////////////////////////////
4
5 #include <iostream>
6 #include <fstream>
7 #include <cctype>
8 #include <iomanip>
9 using namespace std;
10
11 //////////////////////////////////////////////////////////////////
12 // CLASS USED IN PROJECT
13 //////////////////////////////////////////////////////////////////
14
15 class account
16 {
17 int acno;
18 char name[50];
19 int deposit;
20 char type;
21 public:
22 void create_account(); //get data from user
23 void show_account() const; //show data on screen
24 void modify(); //add new data
25 void dep(int); //accept amount and add to balance amount
26 void draw(int); //accept amount and subtract from balance amount
27 void report() const; //show data in tabular format
28 int retacno() const; //return account number
29 int retdeposit() const; //return balance amount
30 char rettype() const; //return type of account
31 friend void same_acno(account&); //avoid same account No.
32 }; //class ends here
33
34 void account:: create_account()
35 {
36 cout << "\n\nEnter The Name of The account Holder : ";
37 cin.ignore();
38 cin.getline(name,50);
39 cout << "\nEnter Type of The account (C/S) : ";
40 cin >> type;
41 type = toupper(type);
42 cout << "\nEnter The Initial amount(>=500 for"
43 << " Saving and >=1000 for current ) : ";
44 cin >> deposit;
45 cout << "\n\n\nAccount Created..";
46 }
47
48 void account:: show_account() const
49 {
50 cout << "\nAccount No. : " << acno;
51 cout << "\nAccount Holder Name : ";
52 cout << name;
53 cout << "\nType of Account : " << type;
54 cout << "\nBalance amount : " << deposit;
55 }
56
57
58 void account:: modify()
59 {
60 cout << "\nAccount No. : " << acno;
61 cout << "\nModify Account Holder Name : ";
62 cin.ignore();
63 cin.getline(name,50);
64 cout << "\nModify Type of Account : ";
65 cin >> type;
66 type = toupper(type);
67 cout << "\nModify Balance amount : ";
68 cin >> deposit;
69 }
70
71
72 void account:: dep(int x)
73 {
74 deposit += x;
75 }
76
77 void account:: draw(int x)
78 {
79 deposit -= x;
80 }
81
82 void account:: report() const
83 {
84 cout << acno << setw(10) << " " << name << setw(10)
85 << " " << type << setw(6) << deposit << endl;
86 }
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
108 void write_account(); //write record in binary file
109 void same_acno(account&); //avoid same account number.
110 void display_sp(int); //display account details given by user
111 void modify_account(int); //modify record of file
112 void delete_account(int); //delete record of file
113 void display_all(); //display all account details
114 void deposit_withdraw(int, int); //desposit/withdraw
115 void intro(); //introductory screen function
116
117 /////////////////////////////////////////////////////////////////
118 // THE MAIN FUNCTION OF PROGRAM
119 /////////////////////////////////////////////////////////////////
120
121 int main()
122 {
123 char ch;
124 int num;
125 intro();
126 do
127 {
128 system("cls");
129 cout << "\n\n\n\tMAIN MENU";
130 cout << "\n\n\t01. NEW ACCOUNT";
131 cout << "\n\n\t02. DEPOSIT AMOUNT";
132 cout << "\n\n\t03. WITHDRAW AMOUNT";
133 cout << "\n\n\t04. BALANCE ENQUIRY";
134 cout << "\n\n\t05. ALL ACCOUNT HOLDER LIST";
135 cout << "\n\n\t06. CLOSE AN ACCOUNT";
136 cout << "\n\n\t07. MODIFY AN ACCOUNT";
137 cout << "\n\n\t08. EXIT";
138 cout << "\n\n\tSelect Your Option (1-8) ";
139 cin >> ch;
140 system("cls");
141 switch(ch)
142 {
143 case '1':
144 write_account();
145 break;
146 case '2':
147 cout << "\n\n\tEnter The account No. : ";
148 cin >> num;
149 deposit_withdraw(num, 1);
150 break;
151 case '3':
152 cout << "\n\n\tEnter The account No. : ";
153 cin >> num;
154 deposit_withdraw(num, 2);
155 break;
156 case '4':
157 cout << "\n\n\tEnter The account No. : ";
158 cin >> num;
159 display_sp(num);
160 break;
161 case '5':
162 display_all();
163 break;
164 case '6':
165 cout << "\n\n\tEnter The account No. : ";
166 cin >> num;
167 delete_account(num);
168 break;
169 case '7':
170 cout << "\n\n\tEnter The account No. : ";
171 cin >> num;
172 modify_account(num);
173 break;
174 case '8':
175 cout << "\n\n\tThanks for using Savings managemnt system";
176 break;
177 default :cout << "\a";
178 }
179 cin.ignore();
180 cin.get();
181 }while(ch!='8');
182 return 0;
183 }
184
185 //////////////////////////////////////////////////////////////////
186 // funtion to Catch Same Account Number
187 //////////////////////////////////////////////////////////////////
188
189 void same_acno(account& ac) {
190 int acno1;
191 ifstream File("account.dat", ios::binary);
192 X:
193 cout << "\nEnter The account No. :";
194 cin >> acno1;
195 while(File.read(reinterpret_cast<char*> (&ac), sizeof(account))) {
196 if(ac.retacno() == acno1) {
197 File.seekg(0);
198 goto X;
199 }
200 }
201 ac.acno = acno1;
202 File.close();
203 }
204
205
206 //////////////////////////////////////////////////////////////////
207 // function to write in file
208 //////////////////////////////////////////////////////////////////
209
210 void write_account()
211 {
212 account ac;
213 same_acno(ac);
214 ac.create_account();
215 ofstream outFile;
216 outFile.open("account.dat",ios::binary|ios::app);
217 outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
218 outFile.close();
219 }
220
221 //////////////////////////////////////////////////////////////////
222 // function to read specific record from file
223 //////////////////////////////////////////////////////////////////
224
225 void display_sp(int n)
226 {
227 account ac;
228 bool flag=false;
229 ifstream inFile;
230 inFile.open("account.dat",ios::binary);
231 if( !inFile )
232 {
233 cout << "File could not be open !! Press any Key...";
234 return;
235 }
236 cout << "\nBALANCE DETAILS\n";
237 while(inFile.read(reinterpret_cast<char *> (&ac),sizeof(account)))
238 {
239 if(ac.retacno() == n)
240 {
241 ac.show_account();
242 flag = true;
243 }
244 }
245 inFile.close();
246 if(flag == false)
247 cout << "\n\nAccount number does not exist";
248 }
249
250
251 //////////////////////////////////////////////////////////////////
252 // function to modify record of file
253 //////////////////////////////////////////////////////////////////
254
255 void modify_account(int n)
256 {
257 bool found = false;
258 account ac;
259 fstream File;
260 File.open("account.dat",ios::binary|ios::in|ios::out);
261 if(!File)
262 {
263 cout << "File could not be open !! Press any Key...";
264 return;
265 }
266 while(!File.eof() && found==false)
267 {
268 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
269 if(ac.retacno() == n)
270 {
271 ac.show_account();
272 cout << "\n\nEnter The New Details of account"<<endl;
273 ac.modify();
274 int pos=(-1)*static_cast<int>(sizeof(account));
275 File.seekp(pos, ios::cur);
276 File.write(reinterpret_cast<char*>(&ac),sizeof(account));
277 cout << "\n\n\t Record Updated";
278 found = true;
279 }
280 }
281 File.close();
282 if(found == false)
283 cout << "\n\n Record Not Found ";
284 }
285
286 //////////////////////////////////////////////////////////////////
287 // function to delete record of file
288 //////////////////////////////////////////////////////////////////
289
290
291 void delete_account(int n)
292 {
293 account ac;
294 ifstream inFile;
295 ofstream outFile;
296 inFile.open("account.dat",ios::binary);
297 if( !inFile )
298 {
299 cout << "File could not be open !! Press any Key...";
300 return;
301 }
302 outFile.open("Temp.dat",ios::binary);
303 inFile.seekg(0,ios::beg);
304 while(inFile.read(reinterpret_cast<char*>(&ac),sizeof(account)))
305 {
306 if(ac.retacno() != n) {
307 outFile.write(reinterpret_cast<char*>(&ac),sizeof(account));
308 }
309 }
310 inFile.close();
311 outFile.close();
312 remove("account.dat");
313 rename("Temp.dat","account.dat");
314 cout << "\n\n\tRecord Deleted ..";
315 }
316
317 //////////////////////////////////////////////////////////////////
318 // function to display all accounts deposit list
319 //////////////////////////////////////////////////////////////////
320
321 void display_all()
322 {
323 account ac;
324 ifstream inFile;
325 inFile.open("account.dat",ios::binary);
326 if(!inFile)
327 {
328 cout << "File could not be open !! Press any Key...";
329 return;
330 }
331 cout << "\n\n\t\tACCOUNT HOLDER LIST\n\n";
332 cout << "====================================================\n";
333 cout << "A/c no. NAME Type Balance\n";
334 cout << "====================================================\n";
335 while(inFile.read(reinterpret_cast<char*>(&ac),sizeof(account)))
336 {
337 ac.report();
338 }
339 inFile.close();
340 }
341
342 //////////////////////////////////////////////////////////////////
343 // function to deposit and withdraw amounts
344 //////////////////////////////////////////////////////////////////
345
346 void deposit_withdraw(int n, int option)
347 {
348 int amt;
349 bool found=false;
350 account ac;
351 fstream File;
352 File.open("account.dat", ios::binary|ios::in|ios::out);
353 if(!File)
354 {
355 cout << "File could not be open !! Press any Key...";
356 return;
357 }
358 while(!File.eof() && found==false)
359 {
360 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
361 if(ac.retacno() == n)
362 {
363 ac.show_account();
364 if(option==1)
365 {
366 cout << "\n\n\tTO DEPOSITE AMOUNT ";
367 cout << "\n\nEnter The amount to be deposited";
368 cin >> amt;
369 ac.dep(amt);
370 }
371 if(option==2)
372 {
373 cout << "\n\n\tTO WITHDRAW AMOUNT ";
374 cout << "\n\nEnter The amount to be withdraw";
375 cin >> amt;
376 int bal = ac.retdeposit()-amt;
377 if((bal < 500 && ac.rettype() == 'S')
378 || (bal < 1000 && ac.rettype() == 'C'))
379 cout << "Insufficience balance";
380 else
381 ac.draw(amt);
382 }
383 int pos=(-1)*static_cast<int>(sizeof(ac));
384 File.seekp(pos, ios::cur);
385 File.write(reinterpret_cast<char*>(&ac),sizeof(account));
386 cout << "\n\n\t Record Updated";
387 found = true;
388 }
389 }
390 File.close();
391 if(found == false)
392 cout << "\n\n Record Not Found ";
393 }
394
395
396 //////////////////////////////////////////////////////////////////
397 // INTRODUCTION FUNCTION
398 //////////////////////////////////////////////////////////////////
399
400 void intro()
401 {
402 cout << "\n\n\n\t\t\tSavings";
403 cout << "\n\n\t\t\tMANAGEMENT";
404 cout << "\n\n\t\t\t SYSTEM";
405 cout << "\n\n\n\n\t\tMADE BY : SOURAV JHA";
406 cout << "\n\n\t\tSCHOOL : RPVV RAJ NIWAS MARG.";
407 cin.get();
408 }
409
410 /////////////////////////////////////////////////////////////////
411 // END OF PROJECT
412 /////////////////////////////////////////////////////////////////

OUTPUT:
//////////////////////////////////////////////////////////// ?

Savings

MANAGEMENT

SYSTEM

MADE BY : SOURAV JHA

SCHOOL : RPVV RAJ NIWAS MARG.


////////////////////////////////////////////////////////////
MAIN MENU

01. NEW ACCOUNT

02. DEPOSIT AMOUNT

03. WITHDRAW AMOUNT

04. BALANCE ENQUIRY

05. ALL ACCOUNT HOLDER LIST

06. CLOSE AN ACCOUNT

07. MODIFY AN ACCOUNT

08. EXIT

Select Your Option (1-8) 1


////////////////////////////////////////////////////////////
Enter The account No. :1

Enter The Name of The account Holder : Saurav

Enter Type of The account (C/S) : C

Enter The Initial amount(>=500 for Saving and >=1000 for current ) : 9348
Account Created..
////////////////////////////////////////////////////////////
Enter The account No. : 1

Account No. : 1
Account Holder Name : Saurav
Type of Account : C
Balance amount : 9348

TO DEPOSITE AMOUNT

Enter The amount to be deposited 1000

Record Updated
////////////////////////////////////////////////////////////
Enter The account No. : 1

Account No. : 1
Account Holder Name : Saurav
Type of Account : C
Balance amount : 10348

TO WITHDRAW AMOUNT

Enter The amount to be withdraw 10000


Insufficience balance

Record Updated
////////////////////////////////////////////////////////////
ACCOUNT HOLDER LIST

====================================================
A/c no. NAME Type Balance
====================================================
1 Saurav C 10348
2 Mukul S 600
3 Nuper C 4000
4 Naveen C 5000
5 Uday S 900
////////////////////////////////////////////////////////////
Enter The account No. : 1

Account No. : 1
Account Holder Name : Saurav
Type of Account : C
Balance amount : 10348

Enter The New Details of account

Account No. : 1
Modify Account Holder Name : Saurav Jha

Modify Type of Account : C

Modify Balance amount : 20000


Record Updated
////////////////////////////////////////////////////////////

Thanks for using Savings managemnt system

////////////////////////////////////////////////////////////

You might also like