csenotes12

C ++ Banking System Project

Apr 14th, 2019
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  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. {
  85.     cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl;
  86. }
  87.  
  88.    
  89. int account::retacno() const
  90. {
  91.     return acno;
  92. }
  93.  
  94. int account::retdeposit() const
  95. {
  96.     return deposit;
  97. }
  98.  
  99. char account::rettype() const
  100. {
  101.     return type;
  102. }
  103.  
  104.  
  105. //***************************************************************
  106. //      function declaration
  107. //****************************************************************
  108. void write_account();   //function to write record in binary file
  109. void display_sp(int);   //function to display account details given by user
  110. void modify_account(int);   //function to modify record of file
  111. void delete_account(int);   //function to delete record of file
  112. void display_all();     //function to display all account details
  113. void deposit_withdraw(int, int); // function to desposit/withdraw amount for given account
  114. void intro();   //introductory screen function
  115.  
  116. //***************************************************************
  117. //      THE MAIN FUNCTION OF PROGRAM
  118. //****************************************************************
  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. : "; cin>>num;
  148.             deposit_withdraw(num, 1);
  149.             break;
  150.         case '3':
  151.             cout<<"\n\n\tEnter The account No. : "; cin>>num;
  152.             deposit_withdraw(num, 2);
  153.             break;
  154.         case '4':
  155.             cout<<"\n\n\tEnter The account No. : "; cin>>num;
  156.             display_sp(num);
  157.             break;
  158.         case '5':
  159.             display_all();
  160.             break;
  161.         case '6':
  162.             cout<<"\n\n\tEnter The account No. : "; cin>>num;
  163.             delete_account(num);
  164.             break;
  165.          case '7':
  166.             cout<<"\n\n\tEnter The account No. : "; cin>>num;
  167.             modify_account(num);
  168.             break;
  169.          case '8':
  170.             cout<<"\n\n\tThanks for using bank managemnt system";
  171.             break;
  172.          default :cout<<"\a";
  173.         }
  174.         cin.ignore();
  175.         cin.get();
  176.     }while(ch!='8');
  177.     return 0;
  178. }
  179.  
  180.  
  181. //***************************************************************
  182. //      function to write in file
  183. //****************************************************************
  184.  
  185. void write_account()
  186. {
  187.     account ac;
  188.     ofstream outFile;
  189.     outFile.open("account.dat",ios::binary|ios::app);
  190.     ac.create_account();
  191.     outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
  192.     outFile.close();
  193. }
  194.  
  195. //***************************************************************
  196. //      function to read specific record from file
  197. //****************************************************************
  198.  
  199. void display_sp(int n)
  200. {
  201.     account ac;
  202.     bool flag=false;
  203.     ifstream inFile;
  204.     inFile.open("account.dat",ios::binary);
  205.     if(!inFile)
  206.     {
  207.         cout<<"File could not be open !! Press any Key...";
  208.         return;
  209.     }
  210.     cout<<"\nBALANCE DETAILS\n";
  211.  
  212.         while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
  213.     {
  214.         if(ac.retacno()==n)
  215.         {
  216.             ac.show_account();
  217.             flag=true;
  218.         }
  219.     }
  220.     inFile.close();
  221.     if(flag==false)
  222.         cout<<"\n\nAccount number does not exist";
  223. }
  224.  
  225.  
  226. //***************************************************************
  227. //      function to modify record of file
  228. //****************************************************************
  229.  
  230. void modify_account(int n)
  231. {
  232.     bool found=false;
  233.     account ac;
  234.     fstream File;
  235.     File.open("account.dat",ios::binary|ios::in|ios::out);
  236.     if(!File)
  237.     {
  238.         cout<<"File could not be open !! Press any Key...";
  239.         return;
  240.     }
  241.     while(!File.eof() && found==false)
  242.     {
  243.         File.read(reinterpret_cast<char *> (&ac), sizeof(account));
  244.         if(ac.retacno()==n)
  245.         {
  246.             ac.show_account();
  247.             cout<<"\n\nEnter The New Details of account"<<endl;
  248.             ac.modify();
  249.             int pos=(-1)*static_cast<int>(sizeof(account));
  250.             File.seekp(pos,ios::cur);
  251.             File.write(reinterpret_cast<char *> (&ac), sizeof(account));
  252.             cout<<"\n\n\t Record Updated";
  253.             found=true;
  254.           }
  255.     }
  256.     File.close();
  257.     if(found==false)
  258.         cout<<"\n\n Record Not Found ";
  259. }
  260.  
  261. //***************************************************************
  262. //      function to delete record of file
  263. //****************************************************************
  264.  
  265.  
  266. void delete_account(int n)
  267. {
  268.     account ac;
  269.     ifstream inFile;
  270.     ofstream outFile;
  271.     inFile.open("account.dat",ios::binary);
  272.     if(!inFile)
  273.     {
  274.         cout<<"File could not be open !! Press any Key...";
  275.         return;
  276.     }
  277.     outFile.open("Temp.dat",ios::binary);
  278.     inFile.seekg(0,ios::beg);
  279.     while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
  280.     {
  281.         if(ac.retacno()!=n)
  282.         {
  283.             outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
  284.         }
  285.     }
  286.     inFile.close();
  287.     outFile.close();
  288.     remove("account.dat");
  289.     rename("Temp.dat","account.dat");
  290.     cout<<"\n\n\tRecord Deleted ..";
  291. }
  292.  
  293. //***************************************************************
  294. //      function to display all accounts deposit list
  295. //****************************************************************
  296.  
  297. void display_all()
  298. {
  299.     account ac;
  300.     ifstream inFile;
  301.     inFile.open("account.dat",ios::binary);
  302.     if(!inFile)
  303.     {
  304.         cout<<"File could not be open !! Press any Key...";
  305.         return;
  306.     }
  307.     cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
  308.     cout<<"====================================================\n";
  309.     cout<<"A/c no.      NAME           Type  Balance\n";
  310.     cout<<"====================================================\n";
  311.     while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
  312.     {
  313.         ac.report();
  314.     }
  315.     inFile.close();
  316. }
  317.  
  318. //***************************************************************
  319. //      function to deposit and withdraw amounts
  320. //****************************************************************
  321.  
  322. void deposit_withdraw(int n, int option)
  323. {
  324.     int amt;
  325.     bool found=false;
  326.     account ac;
  327.     fstream File;
  328.     File.open("account.dat", ios::binary|ios::in|ios::out);
  329.     if(!File)
  330.     {
  331.         cout<<"File could not be open !! Press any Key...";
  332.         return;
  333.     }
  334.     while(!File.eof() && found==false)
  335.     {
  336.         File.read(reinterpret_cast<char *> (&ac), sizeof(account));
  337.         if(ac.retacno()==n)
  338.         {
  339.             ac.show_account();
  340.             if(option==1)
  341.             {
  342.                 cout<<"\n\n\tTO DEPOSITE AMOUNT ";
  343.                 cout<<"\n\nEnter The amount to be deposited";
  344.                 cin>>amt;
  345.                 ac.dep(amt);
  346.             }
  347.             if(option==2)
  348.             {
  349.                 cout<<"\n\n\tTO WITHDRAW AMOUNT ";
  350.                 cout<<"\n\nEnter The amount to be withdraw";
  351.                 cin>>amt;
  352.                 int bal=ac.retdeposit()-amt;
  353.                 if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C'))
  354.                     cout<<"Insufficience balance";
  355.                 else
  356.                     ac.draw(amt);
  357.             }
  358.             int pos=(-1)*static_cast<int>(sizeof(ac));
  359.             File.seekp(pos,ios::cur);
  360.             File.write(reinterpret_cast<char *> (&ac), sizeof(account));
  361.             cout<<"\n\n\t Record Updated";
  362.             found=true;
  363.            }
  364.          }
  365.     File.close();
  366.     if(found==false)
  367.         cout<<"\n\n Record Not Found ";
  368. }
  369.  
  370.  
  371. //***************************************************************
  372. //      INTRODUCTION FUNCTION
  373. //****************************************************************
  374.  
  375.  
  376. void intro()
  377. {
  378.     cout<<"\n\n\n\t  BANK";
  379.     cout<<"\n\n\tMANAGEMENT";
  380.     cout<<"\n\n\t  SYSTEM";
  381.     cout<<"\n\n\n\nMADE BY : your name";
  382.     cout<<"\n\nSCHOOL : your school name";
  383.     cin.get();
  384. }
  385.  
  386. //***************************************************************
  387. //              END OF PROJECT
  388. //***************************************************************
RAW Paste Data