Question: C++ banking program.....I have not learned Class yet. How can I change this code to a simple banking screen. #include #include #include #include using namespace
C++ banking program.....I have not learned "Class" yet. How can I change this code to a simple banking screen.
#include #include #include #include using namespace std; class account { int accountnumber; char name[50]; int deposit; char type; public: void create_account(); void show_account(); void modify_account(); void deposit_funds(int); void draw_funds(int); void get_report(); int get_accountnumber(); int get_funds(); char get_accounttype(); }; void account::create_account() { cout<<" Enter The account Number: "; cin>>accountnumber; cout<<" Enter The Name of The account Holder : "; cin.ignore(); cin.getline(name,50); cout<<" Enter account type (enter s - saving or c - credit): "; cin>>type; type=toupper(type); cout<<" Enter The Initial amount(500 or more for Saving and 1000 or more for current ): "; cin>>deposit; cout<<" Account Created Successfully..."; } void account::show_account() { cout<<" Account Number: "<>type; type=toupper(type); cout<<" Modify Balance amount: "; cin>>deposit; } void account::deposit_funds(int x) { deposit+=x; } void account::draw_funds(int x) { deposit-=x; } void account::get_report() { cout<>opt; system("cls"); switch(opt) { case '1': system("color 02"); write_account(); break; case '2': system("color 03"); cout<<" \tEnter The account No. : "; cin>>num; deposit_withdraw(num, 1); break; case '3': system("color 06"); cout<<" \tEnter The account No. : "; cin>>num; deposit_withdraw(num, 2); break; case '4': system("color 08"); cout<<" \tEnter The account No. : "; cin>>num; display_sp(num); break; case '5': system("color 9"); display_all(); break; case '6': system("color 10"); cout<<" \tEnter The account No. : "; cin>>num; delete_account(num); break; case '7': system("color 11"); cout<<" \tEnter The account No. : "; cin>>num; modify_account(num); break; case '8': system("color 04"); cout<<" \tThanks for using Bank Managemnt System"; break; default :cout<<"Invalid Option "; } cin.ignore(); cin.get(); if(opt=='8') break; } return 0; } void write_account() { account ac; ofstream outFile; outFile.open("account.dat",ios::binary|ios::app); ac.create_account(); outFile.write(reinterpret_cast (&ac), sizeof(account)); outFile.close(); } void display_sp(int n) { account ac; bool flag=false; ifstream inFile; inFile.open("account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<" BALANCE DETAILS "; while(inFile.read(reinterpret_cast (&ac), sizeof(account))) { if(ac.get_accountnumber()==n) { ac.show_account(); flag=true; } } inFile.close(); if(flag==false) cout<<" Account number does not exist"; } void modify_account(int n) { bool found=false; account ac; fstream File; File.open("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 (&ac), sizeof(account)); if(ac.get_accountnumber()==n) { ac.show_account(); cout<<" Enter The New Details of account: "<(sizeof(account)); File.seekp(pos,ios::cur); File.write(reinterpret_cast (&ac), sizeof(account)); cout<<" \t Record Updated..."; found=true; } } File.close(); if(found==false) cout<<" Record Not Found "; } void delete_account(int n) { account ac; ifstream inFile; ofstream outFile; inFile.open("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 (&ac), sizeof(account))) { if(ac.get_accountnumber()!=n) { outFile.write(reinterpret_cast (&ac), sizeof(account)); } } inFile.close(); outFile.close(); remove("account.dat"); rename("Temp.dat","account.dat"); cout<<" \tRecord Deleted..."; } void display_all() { account ac; ifstream inFile; inFile.open("account.dat",ios::binary); if(!inFile) { cout<<"File could not be open !! Press any Key..."; return; } cout<<" \t\tACCOUNT HOLDER LIST "; cout<<"==================================================== "; cout<<"Account No. Name Type Balance "; cout<<"==================================================== "; while(inFile.read(reinterpret_cast (&ac), sizeof(account))) { ac.get_report(); } inFile.close(); } void deposit_withdraw(int n, int option) { int amt; bool found=false; account ac; fstream File; File.open("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 (&ac), sizeof(account)); if(ac.get_accountnumber()==n) { ac.show_account(); if(option==1) { cout<<" \tTO DEPOSITE AMOUNT "; cout<<" Enter The amount to be deposited: "; cin>>amt; ac.deposit_funds(amt); } if(option==2) { cout<<" \tTO WITHDRAW AMOUNT "; cout<<" Enter The amount to be withdraw: "; cin>>amt; int bal=ac.get_funds()-amt; if((bal<500 && ac.get_accounttype()=='S') || (bal<1000 cout<<"insufficience balance"; else ac.draw_funds(amt); } int pos =(-1)*static_cast(sizeof(ac)); File.seekp(pos,ios::cur); File.write(reinterpret_cast (&ac), sizeof(account)); cout<<" \t Record Updated"; found=true; } } File.close(); if(found==false) cout<<" Record Not Found "; }