|
| 1 | +//*************************************************************** |
| 2 | +// HEADER FILE USED IN PROJECT |
| 3 | +//**************************************************************** |
| 4 | + |
| 5 | + |
| 6 | +#include<fstream.h> |
| 7 | +#include<ctype.h> |
| 8 | +#include<iomanip.h> |
| 9 | +#include<conio.h> |
| 10 | +#include<stdio.h> |
| 11 | + |
| 12 | + |
| 13 | +//*************************************************************** |
| 14 | +// CLASS USED IN PROJECT |
| 15 | +//**************************************************************** |
| 16 | + |
| 17 | +class account |
| 18 | +{ |
| 19 | + int acno; |
| 20 | + char name[50]; |
| 21 | + int deposit; |
| 22 | + char type; |
| 23 | +public: |
| 24 | + void create_account(); //function to get data from user |
| 25 | + void show_account(); //function to show data on screen |
| 26 | + void modify(); //function to get new data from user |
| 27 | + void dep(int); //function to accept amount and add to balance amount |
| 28 | + void draw(int); //function to accept amount and subtract from balance amount |
| 29 | + void report(); //function to show data in tabular format |
| 30 | + int retacno(); //function to return account number |
| 31 | + int retdeposit(); //function to return balance amount |
| 32 | + char rettype(); //function to return type of account |
| 33 | +}; //class ends here |
| 34 | + |
| 35 | +void account::create_account() |
| 36 | +{ |
| 37 | + cout<<"\nEnter The account No."; |
| 38 | + cin>>acno; |
| 39 | + cout<<"\n\nEnter The Name of The account Holder : "; |
| 40 | + gets(name); |
| 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() |
| 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<<"\nThe account No."<<acno; |
| 62 | + cout<<"\n\nEnter The Name of The account Holder : "; |
| 63 | + gets(name); |
| 64 | + cout<<"\nEnter Type of The account (C/S) : "; |
| 65 | + cin>>type; |
| 66 | + type=toupper(type); |
| 67 | + cout<<"\nEnter The 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() |
| 83 | +{ |
| 84 | + cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl; |
| 85 | +} |
| 86 | + |
| 87 | +int account::retacno() |
| 88 | +{ |
| 89 | + return acno; |
| 90 | +} |
| 91 | + |
| 92 | +int account::retdeposit() |
| 93 | +{ |
| 94 | + return deposit; |
| 95 | +} |
| 96 | + |
| 97 | +char account::rettype() |
| 98 | +{ |
| 99 | + return type; |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +//*************************************************************** |
| 104 | +// function declaration |
| 105 | +//**************************************************************** |
| 106 | +void write_account(); //function to write record in binary file |
| 107 | +void display_sp(int); //function to display account details given by user |
| 108 | +void modify_account(int); //function to modify record of file |
| 109 | +void delete_account(int); //function to delete record of file |
| 110 | +void display_all(); //function to display all account details |
| 111 | +void deposit_withdraw(int, int); // function to desposit/withdraw amount for given account |
| 112 | +void intro(); //introductory screen function |
| 113 | + |
| 114 | +//*************************************************************** |
| 115 | +// THE MAIN FUNCTION OF PROGRAM |
| 116 | +//**************************************************************** |
| 117 | + |
| 118 | + |
| 119 | +int main() |
| 120 | +{ |
| 121 | + char ch; |
| 122 | + int num; |
| 123 | + clrscr(); |
| 124 | + intro(); |
| 125 | + do |
| 126 | + { |
| 127 | + clrscr(); |
| 128 | + cout<<"\n\n\n\tMAIN MENU"; |
| 129 | + cout<<"\n\n\t01. NEW ACCOUNT"; |
| 130 | + cout<<"\n\n\t02. DEPOSIT AMOUNT"; |
| 131 | + cout<<"\n\n\t03. WITHDRAW AMOUNT"; |
| 132 | + cout<<"\n\n\t04. BALANCE ENQUIRY"; |
| 133 | + cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST"; |
| 134 | + cout<<"\n\n\t06. CLOSE AN ACCOUNT"; |
| 135 | + cout<<"\n\n\t07. MODIFY AN ACCOUNT"; |
| 136 | + cout<<"\n\n\t08. EXIT"; |
| 137 | + cout<<"\n\n\tSelect Your Option (1-8) "; |
| 138 | + cin>>ch; |
| 139 | + clrscr(); |
| 140 | + switch(ch) |
| 141 | + { |
| 142 | + case '1': |
| 143 | + write_account(); |
| 144 | + break; |
| 145 | + case '2': |
| 146 | + cout<<"\n\n\tEnter The account No. : "; cin>>num; |
| 147 | + deposit_withdraw(num, 1); |
| 148 | + break; |
| 149 | + case '3': |
| 150 | + cout<<"\n\n\tEnter The account No. : "; cin>>num; |
| 151 | + deposit_withdraw(num, 2); |
| 152 | + break; |
| 153 | + case '4': |
| 154 | + cout<<"\n\n\tEnter The account No. : "; cin>>num; |
| 155 | + display_sp(num); |
| 156 | + break; |
| 157 | + case '5': |
| 158 | + display_all(); |
| 159 | + break; |
| 160 | + case '6': |
| 161 | + cout<<"\n\n\tEnter The account No. : "; cin>>num; |
| 162 | + delete_account(num); |
| 163 | + break; |
| 164 | + case '7': |
| 165 | + cout<<"\n\n\tEnter The account No. : "; cin>>num; |
| 166 | + modify_account(num); |
| 167 | + break; |
| 168 | + case '8': |
| 169 | + cout<<"\n\n\tThanks for using bank managemnt system"; |
| 170 | + break; |
| 171 | + default :cout<<"\a"; |
| 172 | + } |
| 173 | + getch(); |
| 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((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 | + int flag=0; |
| 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((char *) &ac, sizeof(account))) |
| 210 | + { |
| 211 | + if(ac.retacno()==n) |
| 212 | + { |
| 213 | + ac.show_account(); |
| 214 | + flag=1; |
| 215 | + } |
| 216 | + } |
| 217 | + inFile.close(); |
| 218 | + if(flag==0) |
| 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 | + int found=0; |
| 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.read((char *) &ac, sizeof(account)) && found==0) |
| 239 | + { |
| 240 | + if(ac.retacno()==n) |
| 241 | + { |
| 242 | + ac.show_account(); |
| 243 | + cout<<"\n\nEnter The New Details of account"<<endl; |
| 244 | + ac.modify(); |
| 245 | + int pos=(-1)*sizeof(account); |
| 246 | + File.seekp(pos,ios::cur); |
| 247 | + File.write((char *) &ac, sizeof(account)); |
| 248 | + cout<<"\n\n\t Record Updated"; |
| 249 | + found=1; |
| 250 | + } |
| 251 | + } |
| 252 | + File.close(); |
| 253 | + if(found==0) |
| 254 | + cout<<"\n\n Record Not Found "; |
| 255 | +} |
| 256 | + |
| 257 | +//*************************************************************** |
| 258 | +// function to delete record of file |
| 259 | +//**************************************************************** |
| 260 | + |
| 261 | + |
| 262 | +void delete_account(int n) |
| 263 | +{ |
| 264 | + account ac; |
| 265 | + ifstream inFile; |
| 266 | + ofstream outFile; |
| 267 | + inFile.open("account.dat",ios::binary); |
| 268 | + if(!inFile) |
| 269 | + { |
| 270 | + cout<<"File could not be open !! Press any Key..."; |
| 271 | + return; |
| 272 | + } |
| 273 | + outFile.open("Temp.dat",ios::binary); |
| 274 | + inFile.seekg(0,ios::beg); |
| 275 | + while(inFile.read((char *) &ac, sizeof(account))) |
| 276 | + { |
| 277 | + if(ac.retacno()!=n) |
| 278 | + { |
| 279 | + outFile.write((char *) &ac, sizeof(account)); |
| 280 | + } |
| 281 | + } |
| 282 | + inFile.close(); |
| 283 | + outFile.close(); |
| 284 | + remove("account.dat"); |
| 285 | + rename("Temp.dat","account.dat"); |
| 286 | + cout<<"\n\n\tRecord Deleted .."; |
| 287 | +} |
| 288 | + |
| 289 | +//*************************************************************** |
| 290 | +// function to display all accounts deposit list |
| 291 | +//**************************************************************** |
| 292 | + |
| 293 | +void display_all() |
| 294 | +{ |
| 295 | + account ac; |
| 296 | + ifstream inFile; |
| 297 | + inFile.open("account.dat",ios::binary); |
| 298 | + if(!inFile) |
| 299 | + { |
| 300 | + cout<<"File could not be open !! Press any Key..."; |
| 301 | + return; |
| 302 | + } |
| 303 | + cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n"; |
| 304 | + cout<<"====================================================\n"; |
| 305 | + cout<<"A/c no. NAME Type Balance\n"; |
| 306 | + cout<<"====================================================\n"; |
| 307 | + while(inFile.read((char *) &ac, sizeof(account))) |
| 308 | + { |
| 309 | + ac.report(); |
| 310 | + } |
| 311 | + inFile.close(); |
| 312 | +} |
| 313 | + |
| 314 | +//*************************************************************** |
| 315 | +// function to deposit and withdraw amounts |
| 316 | +//**************************************************************** |
| 317 | + |
| 318 | +void deposit_withdraw(int n, int option) |
| 319 | +{ |
| 320 | + int amt; |
| 321 | + int found=0; |
| 322 | + account ac; |
| 323 | + fstream File; |
| 324 | + File.open("account.dat", ios::binary|ios::in|ios::out); |
| 325 | + if(!File) |
| 326 | + { |
| 327 | + cout<<"File could not be open !! Press any Key..."; |
| 328 | + return; |
| 329 | + } |
| 330 | + while(File.read((char *) &ac, sizeof(account)) && found==0) |
| 331 | + { |
| 332 | + if(ac.retacno()==n) |
| 333 | + { |
| 334 | + ac.show_account(); |
| 335 | + if(option==1) |
| 336 | + { |
| 337 | + cout<<"\n\n\tTO DEPOSITE AMOUNT "; |
| 338 | + cout<<"\n\nEnter The amount to be deposited"; |
| 339 | + cin>>amt; |
| 340 | + ac.dep(amt); |
| 341 | + } |
| 342 | + if(option==2) |
| 343 | + { |
| 344 | + cout<<"\n\n\tTO WITHDRAW AMOUNT "; |
| 345 | + cout<<"\n\nEnter The amount to be withdraw"; |
| 346 | + cin>>amt; |
| 347 | + int bal=ac.retdeposit()-amt; |
| 348 | + if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C')) |
| 349 | + cout<<"Insufficience balance"; |
| 350 | + else |
| 351 | + ac.draw(amt); |
| 352 | + } |
| 353 | + int pos=(-1)* sizeof(ac); |
| 354 | + File.seekp(pos,ios::cur); |
| 355 | + File.write((char *) &ac, sizeof(account)); |
| 356 | + cout<<"\n\n\t Record Updated"; |
| 357 | + found=1; |
| 358 | + } |
| 359 | + } |
| 360 | + File.close(); |
| 361 | + if(found==0) |
| 362 | + cout<<"\n\n Record Not Found "; |
| 363 | +} |
| 364 | + |
| 365 | + |
| 366 | +//*************************************************************** |
| 367 | +// INTRODUCTION FUNCTION |
| 368 | +//**************************************************************** |
| 369 | + |
| 370 | + |
| 371 | +void intro() |
| 372 | +{ |
| 373 | + cout<<"\n\n\n\t BANK"; |
| 374 | + cout<<"\n\n\tMANAGEMENT"; |
| 375 | + cout<<"\n\n\t SYSTEM"; |
| 376 | + cout<<"\n\n\n\nMADE BY : SOUMIK MUKHERJEE"; |
| 377 | + getch(); |
| 378 | +} |
0 commit comments