//**************************************************************************************************************// // This code has been provided by TutorialsArt.com // Distribution of the code is permitted if and only if you do not delete these lines. //**************************************************************************************************************// //*************************************************************** // HEADER FILE USED IN PROJECT //**************************************************************** #include<fstream.h> #include<ctype.h> #include<iomanip.h> #include<conio.h> #include<stdio.h> //*************************************************************** // CLASS USED IN PROJECT //**************************************************************** class cls_account { int acno; char acc_name[50]; int acc_depost; char acc_type; public: void Account_Create(); //function to get data from user void Account_Show(); //function to show data on screen void New_Data_fn(); //function to get new data from user void Add_Balance_fn(int); //function to accept amount and add to balance amount void draw_balance_fn(int); //function to accept amount and subtract from balance amount void show_report_fn(); //function to show data in tabular format int retacno_fn(); //function to return cls_account number int retdeposit_fn(); //function to return balance amount char rettype_fn(); //function to return acc_type of cls_account }; //class ends here void cls_account::Account_Create() { cout<<"\nEnter The cls_account No."; cin>>acno; cout<<"\n\nEnter The Name of The cls_account Holder : "; gets(acc_name); cout<<"\nEnter Type of The cls_account (C/S) : "; cin>>acc_type; acc_type=toupper(acc_type); cout<<"\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : "; cin>>acc_depost; cout<<"\n\n\nAccount Created.."; } void cls_account::Account_Show() { cout<<"\nAccount No. : "<<acno; cout<<"\nAccount Holder Name : "; cout<<acc_name; cout<<"\nType of Account : "<<acc_type; cout<<"\nBalance amount : "<<acc_depost; } void cls_account::New_Data_fn() { cout<<"\nThe cls_account No."<<acno; cout<<"\n\nEnter The Name of The cls_account Holder : "; gets(acc_name); cout<<"\nEnter Type of The cls_account (C/S) : "; cin>>acc_type; acc_type=toupper(acc_type); cout<<"\nEnter The amount : "; cin>>acc_depost; } void cls_account::Add_Balance_fn(int x) { acc_depost+=x; } void cls_account::draw_balance_fn(int x) { acc_depost-=x; } void cls_account::show_report_fn() { cout<<acno<<setw(10)<<" "<<acc_name<<setw(10)<<" "<<acc_type<<setw(6)<<acc_depost<<endl; } int cls_account::retacno_fn() { return acno; } int cls_account::retdeposit_fn() { return acc_depost; } char cls_account::rettype_fn() { return acc_type; } //*************************************************************** // function declaration //**************************************************************** void write_account(); //function to write record in binary file void display_sp(int); //function to display cls_account details given by user void modify_account(int); //function to New_Data_fn record of file void delete_account(int); //function to delete record of file void display_all(); //function to display all cls_account details void deposit_withdraw(int, int); // function to desposit/withdraw amount for given cls_account void intro_fn(); //introductory screen function //*************************************************************** // THE MAIN FUNCTION OF PROGRAM //**************************************************************** int main() { char ch; int num; clrscr(); intro_fn(); do { clrscr(); cout<<"\n\n\n\tMAIN MENU"; cout<<"\n\n\t01. NEW ACCOUNT"; cout<<"\n\n\t02. DEPOSIT AMOUNT"; cout<<"\n\n\t03. WITHDRAW AMOUNT"; cout<<"\n\n\t04. BALANCE ENQUIRY"; cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST"; cout<<"\n\n\t06. CLOSE AN ACCOUNT"; cout<<"\n\n\t07. MODIFY AN ACCOUNT"; cout<<"\n\n\t08. EXIT"; cout<<"\n\n\tSelect Your Option (1-8) "; cin>>ch; clrscr(); switch(ch) { case '1': write_account(); break; case '2': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; deposit_withdraw(num, 1); break; case '3': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; deposit_withdraw(num, 2); break; case '4': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; display_sp(num); break; case '5': display_all(); break; case '6': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; delete_account(num); break; case '7': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; modify_account(num); break; case '8': cout<<"\n\n\tThanks for using bank managemnt system"; break; default :cout<<"\a"; } getch(); }while(ch!='8'); return 0; } //*************************************************************** // function to write in file //**************************************************************** void write_account() { cls_account ac; ofstream outFile; outFile.open("cls_account.dat",ios::binary|ios::app); ac.Account_Create(); outFile.write((char *) &ac, sizeof(cls_account)); outFile.close(); } //*************************************************************** // function to read specific record from file //**************************************************************** void display_sp(int n) { cls_account ac; int flag=0; ifstream inFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\nBALANCE DETAILS\n"; while(inFile.read((char *) &ac, sizeof(cls_account))) { if(ac.retacno_fn()==n) { ac.Account_Show(); flag=1; } } inFile.close(); if(flag==0) cout<<"\n\nAccount number does not exist"; } //*************************************************************** // function to New_Data_fn record of file //**************************************************************** void modify_account(int n) { int found=0; cls_account ac; fstream File; File.open("cls_account.dat",ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(File.read((char *) &ac, sizeof(cls_account)) && found==0) { if(ac.retacno_fn()==n) { ac.Account_Show(); cout<<"\n\nEnter The New Details of cls_account"<<endl; ac.New_Data_fn(); int pos=(-1)*sizeof(cls_account); File.seekp(pos,ios::cur); File.write((char *) &ac, sizeof(cls_account)); cout<<"\n\n\t Record Updated"; found=1; } } File.close(); if(found==0) cout<<"\n\n Record Not Found "; } //*************************************************************** // function to delete record of file //**************************************************************** void delete_account(int n) { cls_account ac; ifstream inFile; ofstream outFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } outFile.open("Temp.dat",ios::binary); inFile.seekg(0,ios::beg); while(inFile.read((char *) &ac, sizeof(cls_account))) { if(ac.retacno_fn()!=n) { outFile.write((char *) &ac, sizeof(cls_account)); } } inFile.close(); outFile.close(); remove("cls_account.dat"); rename("Temp.dat","cls_account.dat"); cout<<"\n\n\tRecord Deleted .."; } //*************************************************************** // function to display all accounts acc_depost list //**************************************************************** void display_all() { cls_account ac; ifstream inFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n"; cout<<"====================================================\n"; cout<<"A/c no. NAME Type Balance\n"; cout<<"====================================================\n"; while(inFile.read((char *) &ac, sizeof(cls_account))) { ac.show_report_fn(); } inFile.close(); } //*************************************************************** // function to acc_depost and withdraw amounts //**************************************************************** void deposit_withdraw(int n, int option) { int amt; int found=0; cls_account ac; fstream File; File.open("cls_account.dat", ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(File.read((char *) &ac, sizeof(cls_account)) && found==0) { if(ac.retacno_fn()==n) { ac.Account_Show(); if(option==1) { cout<<"\n\n\tTO DEPOSITE AMOUNT "; cout<<"\n\nEnter The amount to be deposited"; cin>>amt; ac.Add_Balance_fn(amt); } if(option==2) { cout<<"\n\n\tTO WITHDRAW AMOUNT "; cout<<"\n\nEnter The amount to be withdraw"; cin>>amt; int bal=ac.retdeposit_fn()-amt; if((bal<500 && ac.rettype_fn()=='S') || (bal<1000 && ac.rettype_fn()=='C')) cout<<"Insufficience balance"; else ac.draw_balance_fn(amt); } int pos=(-1)* sizeof(ac); File.seekp(pos,ios::cur); File.write((char *) &ac, sizeof(cls_account)); cout<<"\n\n\t Record Updated"; found=1; } } File.close(); if(found==0) cout<<"\n\n Record Not Found "; } //*************************************************************** // INTRODUCTION FUNCTION //**************************************************************** void intro_fn() { cout<<"\n\n\n\t BANK"; cout<<"\n\n\tMANAGEMENT"; cout<<"\n\n\t SYSTEM"; cout<<"\n\n\n\nMADE BY : your acc_name"; cout<<"\n\nSCHOOL : your school acc_name"; getch(); } //*************************************************************** // END OF PROJECT //*************************************************************** //*************************************************************** // HEADER FILE USED IN PROJECT //**************************************************************** #include<iostream> #include<fstream> #include<cctype> #include<iomanip> using namespace std; //*************************************************************** // CLASS USED IN PROJECT //**************************************************************** class cls_account { int acno; char acc_name[50]; int acc_depost; char acc_type; public: void Account_Create(); //function to get data from user void Account_Show() const; //function to show data on screen void New_Data_fn(); //function to add new data void Add_Balance_fn(int); //function to accept amount and add to balance amount void draw_balance_fn(int); //function to accept amount and subtract from balance amount void show_report_fn() const; //function to show data in tabular format int retacno_fn() const; //function to return cls_account number int retdeposit_fn() const; //function to return balance amount char rettype_fn() const; //function to return acc_type of cls_account }; //class ends here void cls_account::Account_Create() { cout<<"\nEnter The cls_account No. :"; cin>>acno; cout<<"\n\nEnter The Name of The cls_account Holder : "; cin.ignore(); cin.getline(acc_name,50); cout<<"\nEnter Type of The cls_account (C/S) : "; cin>>acc_type; acc_type=toupper(acc_type); cout<<"\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : "; cin>>acc_depost; cout<<"\n\n\nAccount Created.."; } void cls_account::Account_Show() const { cout<<"\nAccount No. : "<<acno; cout<<"\nAccount Holder Name : "; cout<<acc_name; cout<<"\nType of Account : "<<acc_type; cout<<"\nBalance amount : "<<acc_depost; } void cls_account::New_Data_fn() { cout<<"\nAccount No. : "<<acno; cout<<"\nModify Account Holder Name : "; cin.ignore(); cin.getline(acc_name,50); cout<<"\nModify Type of Account : "; cin>>acc_type; acc_type=toupper(acc_type); cout<<"\nModify Balance amount : "; cin>>acc_depost; } void cls_account::Add_Balance_fn(int x) { acc_depost+=x; } void cls_account::draw_balance_fn(int x) { acc_depost-=x; } void cls_account::show_report_fn() const { cout<<acno<<setw(10)<<" "<<acc_name<<setw(10)<<" "<<acc_type<<setw(6)<<acc_depost<<endl; } int cls_account::retacno_fn() const { return acno; } int cls_account::retdeposit_fn() const { return acc_depost; } char cls_account::rettype_fn() const { return acc_type; } //*************************************************************** // function declaration //**************************************************************** void write_account(); //function to write record in binary file void display_sp(int); //function to display cls_account details given by user void modify_account(int); //function to New_Data_fn record of file void delete_account(int); //function to delete record of file void display_all(); //function to display all cls_account details void deposit_withdraw(int, int); // function to desposit/withdraw amount for given cls_account void intro_fn(); //introductory screen function //*************************************************************** // THE MAIN FUNCTION OF PROGRAM //**************************************************************** int main() { char ch; int num; intro_fn(); do { system("cls"); cout<<"\n\n\n\tMAIN MENU"; cout<<"\n\n\t01. NEW ACCOUNT"; cout<<"\n\n\t02. DEPOSIT AMOUNT"; cout<<"\n\n\t03. WITHDRAW AMOUNT"; cout<<"\n\n\t04. BALANCE ENQUIRY"; cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST"; cout<<"\n\n\t06. CLOSE AN ACCOUNT"; cout<<"\n\n\t07. MODIFY AN ACCOUNT"; cout<<"\n\n\t08. EXIT"; cout<<"\n\n\tSelect Your Option (1-8) "; cin>>ch; system("cls"); switch(ch) { case '1': write_account(); break; case '2': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; deposit_withdraw(num, 1); break; case '3': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; deposit_withdraw(num, 2); break; case '4': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; display_sp(num); break; case '5': display_all(); break; case '6': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; delete_account(num); break; case '7': cout<<"\n\n\tEnter The cls_account No. : "; cin>>num; modify_account(num); break; case '8': cout<<"\n\n\tThanks for using bank managemnt system"; break; default :cout<<"\a"; } cin.ignore(); cin.get(); }while(ch!='8'); return 0; } //*************************************************************** // function to write in file //**************************************************************** void write_account() { cls_account ac; ofstream outFile; outFile.open("cls_account.dat",ios::binary|ios::app); ac.Account_Create(); outFile.write(reinterpret_cast<char *> (&ac), sizeof(cls_account)); outFile.close(); } //*************************************************************** // function to read specific record from file //**************************************************************** void display_sp(int n) { cls_account ac; bool flag=false; ifstream inFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\nBALANCE DETAILS\n"; while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(cls_account))) { if(ac.retacno_fn()==n) { ac.Account_Show(); flag=true; } } inFile.close(); if(flag==false) cout<<"\n\nAccount number does not exist"; } //*************************************************************** // function to New_Data_fn record of file //**************************************************************** void modify_account(int n) { bool found=false; cls_account ac; fstream File; File.open("cls_account.dat",ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&ac), sizeof(cls_account)); if(ac.retacno_fn()==n) { ac.Account_Show(); cout<<"\n\nEnter The New Details of cls_account"<<endl; ac.New_Data_fn(); int pos=(-1)*static_cast<int>(sizeof(cls_account)); File.seekp(pos,ios::cur); File.write(reinterpret_cast<char *> (&ac), sizeof(cls_account)); cout<<"\n\n\t Record Updated"; found=true; } } File.close(); if(found==false) cout<<"\n\n Record Not Found "; } //*************************************************************** // function to delete record of file //**************************************************************** void delete_account(int n) { cls_account ac; ifstream inFile; ofstream outFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } outFile.open("Temp.dat",ios::binary); inFile.seekg(0,ios::beg); while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(cls_account))) { if(ac.retacno_fn()!=n) { outFile.write(reinterpret_cast<char *> (&ac), sizeof(cls_account)); } } inFile.close(); outFile.close(); remove("cls_account.dat"); rename("Temp.dat","cls_account.dat"); cout<<"\n\n\tRecord Deleted .."; } //*************************************************************** // function to display all accounts acc_depost list //**************************************************************** void display_all() { cls_account ac; ifstream inFile; inFile.open("cls_account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n"; cout<<"====================================================\n"; cout<<"A/c no. NAME Type Balance\n"; cout<<"====================================================\n"; while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(cls_account))) { ac.show_report_fn(); } inFile.close(); } //*************************************************************** // function to acc_depost and withdraw amounts //**************************************************************** void deposit_withdraw(int n, int option) { int amt; bool found=false; cls_account ac; fstream File; File.open("cls_account.dat", ios::binary|ios::in|ios::out); if(!File) { cout<<"File could not be open !! Press any Key..."; return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&ac), sizeof(cls_account)); if(ac.retacno_fn()==n) { ac.Account_Show(); if(option==1) { cout<<"\n\n\tTO DEPOSITE AMOUNT "; cout<<"\n\nEnter The amount to be deposited"; cin>>amt; ac.Add_Balance_fn(amt); } if(option==2) { cout<<"\n\n\tTO WITHDRAW AMOUNT "; cout<<"\n\nEnter The amount to be withdraw"; cin>>amt; int bal=ac.retdeposit_fn()-amt; if((bal<500 && ac.rettype_fn()=='S') || (bal<1000 && ac.rettype_fn()=='C')) cout<<"Insufficience balance"; else ac.draw_balance_fn(amt); } int pos=(-1)*static_cast<int>(sizeof(ac)); File.seekp(pos,ios::cur); File.write(reinterpret_cast<char *> (&ac), sizeof(cls_account)); cout<<"\n\n\t Record Updated"; found=true; } } File.close(); if(found==false) cout<<"\n\n Record Not Found "; } //*************************************************************** // INTRODUCTION FUNCTION //**************************************************************** void intro_fn() { cout<<"\n\n\n\t BANK"; cout<<"\n\n\tMANAGEMENT"; cout<<"\n\n\t SYSTEM"; cout<<"\n\n\n\nMADE BY : your acc_name"; cout<<"\n\nSCHOOL : your school acc_name"; cin.get(); } //*************************************************************** // END OF PROJECT //***************************************************************