Advertisement
Kartik_Sharma

Untitled

Jul 1st, 2012
2,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.81 KB | None | 0 0
  1. /*
  2. ©kartik
  3. ------------------Notes-----------------
  4. You are allowed to use/edit this file.
  5. Give me some credit if posting it.
  6. ------------------------------------------
  7. A very simple C++ program for Bank Management.
  8.  
  9. _____________FEATURES______________
  10.  
  11. 1. Login / Register using File_System
  12. 2. Auto Generating Account Number
  13. 3. Password input in * characters.(You wont see the pass).
  14. 4. Transfer Money to any other account.
  15. 5. Deposit/Withdraw Money
  16. 6. Search entire account database.(Search using Name, Address , Address!!!!)
  17. 7. Ability to Edit your account details.
  18. 8. Ability to Delete an Account.
  19. 9. Search Transactions made.(Using date)
  20. 10. Inputs Date automatically
  21. 11. Ability to store 100 transactions,(Can be increased/decreased).
  22. 12. View Last 10 Transactions.
  23. 13. Date Entry in Fancy Style
  24.  
  25. And More....
  26. */
  27. #include <iostream>
  28. #include <conio.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <fstream>
  32. #include <process.h>
  33. #include <cstdlib>
  34. #include <time.h>
  35. #include <string.h>
  36. #include <dos.h>
  37. #include <ctype.h>
  38.  
  39. using namespace std;
  40.  
  41.  
  42. class bank
  43. {
  44.     long pAcc;//Account Number
  45.     char pass[32];//Password
  46.     char pName[30];
  47.     char pAddr[200];
  48.     unsigned long long pMobile;
  49.     int balance;
  50.     char ltran[100][100];
  51.     public:
  52.  
  53.     void NewAccount();
  54.     void Login();
  55.     void Transact();
  56.     void Transfer();
  57.     void Remove();
  58.     void Show();
  59.     void Search();
  60.     void edit(long);
  61.     void task(long);
  62.     void pre(long);
  63.     void vfull(long);
  64. };
  65.  
  66. void bank::vfull(long Acc)
  67. {
  68.     cout<<"\n\n1. Search by Date\n2. View All Data \n\n...";
  69.     int a;
  70.     cin>>a;
  71.     if(a==2)
  72.     {
  73.         ifstream file;
  74.         file.open("Bank.dat",ios::binary);
  75.         while(file.read((char *)this,sizeof(bank)))
  76.             if(pAcc == Acc) break;
  77.         for(int i=0;i<100 && ltran[i][0]!='\0';++i)
  78.         {
  79.             cout<<"\n"<<ltran[i];
  80.             if(i%10 == 0 && i!= 0) getch();
  81.         }
  82.         getch();
  83.         file.close();
  84.     }
  85.     if(a==1)
  86.     {
  87.         cout<<"Enter Date (DD/MM/YYYY) :  __/__/____\b\b\b\b\b\b\b\b\b\b";
  88.         char a;
  89.         char sDate[8];
  90.         int i=0;
  91.         for(i;;)
  92.             {
  93.                     a=getch();
  94.                     if (a>='0'&&a<='9'&&i<8)
  95.                     {
  96.                         cout<<a;
  97.                         sDate[i]=a;
  98.                         ++i;
  99.                         if (i==2 || i == 4)   cout<<"/";
  100.                     }
  101.                     else if(a=='\b'&&i>0&&i<9)
  102.                     {
  103.                         if(i==2||i==4)
  104.                         {
  105.                             cout<<"\b\b_\b";
  106.                         }
  107.                         else
  108.                         cout<<"\b_\b";
  109.                         --i;
  110.  
  111.                     }
  112.                     else if(a==13)
  113.                     {
  114.                         if(i==8)
  115.                         {
  116.                         sDate[8]='\0';
  117.                         break;
  118.                         }
  119.                     }
  120.  
  121.             }
  122.         ifstream file;
  123.         file.open("Bank.dat",ios::binary);
  124.         while(file.read((char *)this,sizeof(bank)))
  125.             if(pAcc == Acc) break;
  126.         int j,k;
  127.         int ffound= 0;
  128.         for(i =0;ltran[i][0]!='\0';++i)
  129.         {
  130.             int found = 0;
  131.             for(j=0,k=0;ltran[i][j]!='\0'&& sDate[k]!='\0';)
  132.             {
  133.                 if(toupper(ltran[i][j])==toupper(sDate[k]))
  134.                 {
  135.                     ++k;
  136.                     ++j;
  137.                     found = 1;
  138.                     ffound= 1;
  139.                 }
  140.                 else
  141.                 {
  142.                     found = 0;
  143.                     ++j;
  144.                 }
  145.             }
  146.             if(found == 1)
  147.             {
  148.                 cout<<"\n";
  149.                 cout<<"\n"<<ltran[i];
  150.             }
  151.         }
  152.         if(ffound == 0) cout<<"\n\nNo Data found for "<<sDate;
  153.         getch();
  154.  
  155.     }
  156. }
  157.  
  158. void bank::pre(long Acc)
  159. {
  160.     ifstream file;
  161.     file.open("Bank.dat",ios::binary);
  162.     file.seekg(0);
  163.     while(file.read((char*)this,sizeof(bank)))
  164.     {
  165.         if(Acc==pAcc) break;
  166.     }
  167.     cout<<"\n\n--------------------------Account Summary-----------------------------";
  168.     cout<<"\nName : "<<pName<<"\nAddress : "<<pAddr<<"\nPhone Number : "<<pMobile<<"\nBalance : "<<balance;
  169.     cout<<"\n\nDo you wish to view last 10 transaction ? : ";
  170. }
  171. void bank::edit(long Acc)
  172. {
  173.     int c = 3;
  174.     fstream log;
  175.     log.open("Bank.dat",ios::binary|ios::in|ios::out);
  176.     log.seekg(0);
  177.     while(log.read((char*)this,sizeof(bank)))
  178.     {
  179.         if(Acc==pAcc)
  180.             break;
  181.     }
  182.     PASSINPUT:
  183.     cout<<"\nEnter Current Password to continue ("<<c<<" chances remaining ): ";
  184.     char npass[32];
  185.     int i;
  186.     char a;
  187.     for(i=0;;)
  188.     {
  189.         char a = getch();
  190.         if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
  191.         {
  192.             npass[i]=a;
  193.             cout<<"*";
  194.             ++i;
  195.         }
  196.         if(a=='\b'&&i>=1)
  197.         {
  198.             --i;
  199.             cout<<"\b \b";
  200.         }
  201.         if(a=='\r')
  202.         {
  203.             npass[i]='\0';
  204.             break;
  205.         }
  206.     }
  207.     if(i<=5)
  208.     {
  209.         cout<<"\n\nMinimum 6 digits needed.";
  210.         getch();
  211.         goto PASSINPUT;
  212.     }
  213.     int check=0;
  214.     int j;
  215.     for(i=0,j=0;npass[i]!='\0'&&pass[j]!='\0';++i,++j)
  216.     {
  217.         if(pass[j]!=npass[i])
  218.         {
  219.             check = 0;
  220.             break;
  221.         }
  222.         else check = 1;
  223.     }
  224.     if(check == 0)
  225.     {
  226.         --c;
  227.         if(c>=1)
  228.         {
  229.         cout<<"\nWrong Password.";
  230.         cout<<"\nTry Again.\n\n";
  231.         getch();
  232.         goto PASSINPUT;
  233.         }
  234.         else
  235.         {
  236.             cout<<"\nYou entered wrong password 3 times. Terminating the program.";
  237.             getch();
  238.             exit(0);
  239.         }
  240.     }
  241.     system("cls");
  242.     cout<<"Enter New Data";
  243.     cout<<"\n\nName (enter dot(.) to keep same) : ";
  244.     char nname[32];
  245.     fflush(stdin);
  246.     gets(nname);
  247.     cout<<"\nAddress (enter dot(.) to keep same) : ";
  248.     fflush(stdin);
  249.     char nAddr[200];
  250.     gets(nAddr);
  251.     cout<<"\nMobile (enter 0 to keep same) : ";
  252.     unsigned long long nMobile;
  253.     cin>>nMobile;
  254.     PASS:
  255.     system("cls");
  256.     cout<<"Enter New Data"<<"\n\nName (enter dot(.) to keep same) : "<<nname<<"\n\nAddress (enter dot(.) to keep same) : "<<nAddr<<"\n\nMobile (enter 0 to keep same) : "<<nMobile;
  257.     cout<<"\n\nPassword : ";
  258.     for(i=0;;)
  259.     {
  260.         char a = getch();
  261.         if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
  262.         {
  263.             npass[i]=a;
  264.             cout<<"*";
  265.             ++i;
  266.         }
  267.         if(a=='\b'&&i>=1)
  268.         {
  269.             --i;
  270.             cout<<"\b \b";
  271.         }
  272.         if(a=='\r')
  273.         {
  274.             npass[i]='\0';
  275.             break;
  276.         }
  277.     }
  278.     if(i<=5)
  279.     {
  280.         cout<<"\n\nMinimum 6 digits needed.";
  281.         getch();
  282.         goto PASS;
  283.     }
  284.     if(nname[0]!='.') strcpy(pName,nname);
  285.     if(nAddr[0]!='.') strcpy(pAddr,nAddr);
  286.     if(nMobile !=0) pMobile = nMobile;
  287.     strcpy(pass,npass);
  288.     int pos = (-1) * sizeof(bank);
  289.     log.seekp(pos,ios::cur);
  290.     log.write((char*)this,sizeof(bank));
  291.     cout<<"\n\nNew Data is : ";
  292.     cout<<"\nName : "<<pName<<"\nAddress : "<<pAddr<<"\nMobile : "<<pMobile<<"\nPassword : "<<pass;
  293.     getch();
  294.     log.close();
  295. }
  296. void bank::task(long Acc)
  297. {
  298.     START:
  299.     system("cls");
  300.     cout<<"Welcome "<<pName<<"\n";
  301.     cout<<"\nChoose an operation : \n1. Edit Profile\n2. Delete Account\n3. Transfer Money\n4. Withdraw/Deposit Money\n5. Account Summary\n6. Last 10 Transactions\n7. View Full Record\n8. Log Out\n\n...";
  302.     int a;
  303.     cin>>a;
  304.     if(a== 7)
  305.     {
  306.         vfull(Acc);
  307.         goto START;
  308.     }
  309.     if(a==1)
  310.     {
  311.         edit(Acc);
  312.         goto START;
  313.     }
  314.     if(a==3)
  315.     {
  316.         cout<<"\nEnter the amount you want to Transfer : ";
  317.         long amt;
  318.         cin>>amt;
  319.         if(amt>balance)
  320.         {
  321.             cout<<"\nAmount must be less than or equal to "<<balance;
  322.             getch();
  323.             goto START;
  324.  
  325.         }
  326.         else if(amt<=0)
  327.         {
  328.             cout<<"\nAmount cant be negative or zero.";
  329.             getch();
  330.             goto START;
  331.         }
  332.         else
  333.         {
  334.             time_t rawtime;
  335.             struct tm * timeinfo;
  336.             time ( &rawtime );
  337.             timeinfo = localtime ( &rawtime );
  338.             cout<<"\n\nDestination Account Number : ";
  339.             long dAcc;
  340.             cin>>dAcc;
  341.             int found=1;
  342.             char dName[32];
  343.             char mName[32];
  344.             fstream file;
  345.             file.open("Bank.dat",ios::in|ios::out|ios::binary);
  346.             file.seekg(0);
  347.             while(file.read((char*)this,sizeof(bank)))
  348.             {
  349.                 if(pAcc==dAcc)
  350.                 {
  351.                     found = 1;
  352.                     break;
  353.                 }
  354.                 else found = 0;
  355.  
  356.             }
  357.             if(found == 0)
  358.             {
  359.                 cout<<"\n\nAccount not found.";
  360.                 getch();
  361.                 goto START;
  362.             }
  363.             strcpy(dName,pName);
  364.             file.seekg(0);
  365.             while(file.read((char*)this,sizeof(bank)))
  366.             {
  367.                 if(pAcc == Acc) break;
  368.             }
  369.             strcpy(mName,pName);
  370.             int pos = (-1)*(sizeof(bank));
  371.             balance -= amt;
  372.             file.seekp(pos,ios::cur);
  373.             int i;
  374.             for(i=99;i>0;--i)
  375.             {
  376.                 strcpy(ltran[i],ltran[i-1]);
  377.             }
  378.             char str[200];
  379.             char str1[200];
  380.             strftime (str1,100,"[%d/%m/%Y : %X]",timeinfo);
  381.             sprintf(str,"[TRANSFER] Rs %d to %s(%d) << %s",amt,dName,dAcc,str1);
  382.             strcpy(ltran[0],str);
  383.             file.write((char*)this,sizeof(bank));
  384.             file.seekg(0);
  385.             while(file.read((char*)this,sizeof(bank)))
  386.             {
  387.                 if(pAcc==dAcc) break;
  388.             }
  389.             balance+=amt;
  390.             file.seekp(pos,ios::cur);
  391.             for(i=99;i>0;--i)
  392.             {
  393.                 strcpy(ltran[i],ltran[i-1]);
  394.             }
  395.             strftime (str1,100,"[%d/%m/%Y : %X]",timeinfo);
  396.             sprintf(str,"[RECEIVED] Rs %d from %s(%d) << %s",amt,mName,Acc,str1);
  397.             strcpy(ltran[0],str);
  398.             file.write((char*)this,sizeof(bank));
  399.             file.close();
  400.             sprintf(str,"[TRANSFER] Rs %d to %s(%d) << %s",amt,dName,dAcc,str1);
  401.             cout<<"\n\n"<<str;
  402.             getch();
  403.             goto START;
  404.         }
  405.     }
  406.     if(a==5)
  407.     {
  408.         pre(Acc);
  409.         char y;
  410.         cin>>y;
  411.         if(y=='y'||y=='Y')
  412.             a=6;
  413.         else  goto START;
  414.     }
  415.     if(a==6)
  416.     {
  417.         cout<<"\n\n========================LAST 10 TRANSACTIONS=========================";
  418.         ifstream file;
  419.         file.open("Bank.dat",ios::binary);
  420.         file.seekg(0);
  421.         while(file.read((char*)this,sizeof(bank)))
  422.         {
  423.             if(pAcc == Acc) break;
  424.         }
  425.         for( int i= 0;i<10;++i)
  426.             cout<<"\n"<<ltran[i];
  427.         getch();
  428.         goto START;
  429.     }
  430.     if(a==2)
  431.     {
  432.         cout<<"Are you sure you want to delete this account. : ";
  433.         char ans;
  434.         cin>>ans;
  435.         if(ans=='Y'||ans=='y')
  436.         {
  437.         cout<<"\n\nDeleting your account";
  438.         ifstream file;
  439.         file.open("Bank.dat",ios::binary);
  440.         ofstream temp;
  441.         temp.open("Temp.dat",ios::binary);
  442.         while(file.read((char*)this,sizeof(bank)))
  443.         {
  444.             if(Acc!=pAcc) temp.write((char*)this,sizeof(bank));
  445.         }
  446.         file.close();
  447.         temp.close();
  448.         remove("Bank.dat");
  449.         rename("Temp.dat","Bank.dat");
  450.         cout<<"\n\nYour account was successfully deleted.";
  451.         getch();
  452.         goto START;
  453.         }
  454.         else goto START;
  455.     }
  456.     if(a==4)
  457.     {
  458.         cout<<"\n\n1. Withdraw\n2. Deposit\n\n...";
  459.         int am;
  460.         int amo;
  461.         cin>>am;
  462.         fstream file;
  463.         file.open("Bank.dat",ios::in|ios::out|ios::binary);
  464.         file.seekp(0);
  465.         while(file.read((char*)this,sizeof(bank)))
  466.         {
  467.             if(Acc==pAcc) break;
  468.         }
  469.         if(am == 1)
  470.         {
  471.             cout<<"\nEnter amount : ";
  472.             cin>>amo;
  473.             if(balance < amo)
  474.             {
  475.                 cout<<"\nInsufficient Balace .";
  476.                 cout<<"\nYou can withdraw max "<<balance<<" Rs.";
  477.                 getch();
  478.                 goto START;
  479.             }
  480.             else
  481.             {
  482.                 amo = -1 * amo;
  483.                 goto TASK;
  484.             }
  485.  
  486.         }
  487.         else if(am == 2) {
  488.         cout<<"\nEnter amount : ";
  489.         cin>>amo;
  490.         amo = +1*amo;
  491.         goto TASK;}
  492.         else
  493.         {
  494.             cout<<"\n\nWrong Choice.";
  495.             getch();
  496.             goto START;
  497.         }
  498.         TASK:
  499.         time_t rawtime;
  500.         struct tm * timeinfo;
  501.         time ( &rawtime );
  502.         timeinfo = localtime ( &rawtime );
  503.         cout<<"\nTransaction was successful.";
  504.         int pos = -1 * sizeof(bank);
  505.         file.seekp(pos,ios::cur);
  506.         balance += amo;
  507.         int i;
  508.         for(i=99;i>0;--i)
  509.         {
  510.             strcpy(ltran[i],ltran[i-1]);
  511.         }
  512.         char str1[200];
  513.         char str[200];
  514.         if(am == 1)
  515.         {
  516.         amo = -1 * amo;
  517.         strftime(str1,100,"[%d/%m/%Y : %X]",timeinfo);
  518.         sprintf(str,"[[Withdraw] Rs %d  << %s",amo,str1);
  519.         }
  520.         else if(am == 2)
  521.         {
  522.             strftime (str1,100,"[%d/%m/%Y : %X]",timeinfo);
  523.             sprintf(str,"[Deposit] Rs %d  << %s",amo,str1);
  524.         }
  525.         strcpy(ltran[0],str);
  526.         file.write((char*)this,sizeof(bank));
  527.         cout<<"\n\n"<<str;
  528.         getch();
  529.         goto START;
  530.     }
  531. }
  532. void bank::Login()
  533. {
  534.     int c = 3;
  535.     PASSINPUT:
  536.     system("cls");
  537.     cout<<"--------------------------LOGIN-----------------------------";
  538.     cout<<"\n\n"<<c<<" chances remaining.\n\nAccount Number << ";
  539.     long Acc;
  540.     cin >>Acc;
  541.     cout<<"\nPassword << ";
  542.     int i;
  543.     char npass[32];
  544.     char a;
  545.     for(i=0;;)
  546.     {
  547.         char a = getch();
  548.         if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
  549.         {
  550.             npass[i]=a;
  551.             cout<<"*";
  552.             ++i;
  553.         }
  554.         if(a=='\b'&&i>=1)
  555.         {
  556.             --i;
  557.             cout<<"\b \b";
  558.         }
  559.         if(a=='\r')
  560.         {
  561.             npass[i]='\0';
  562.             break;
  563.         }
  564.     }
  565.     if(i<=5)
  566.     {
  567.         cout<<"\n\nMinimum 6 digits needed.";
  568.         getch();
  569.         goto PASSINPUT;
  570.     }
  571.     ifstream log;
  572.     log.open("Bank.dat",ios::binary);
  573.     log.seekg(0);
  574.     int check=0;
  575.     while(log.read((char *)this,sizeof(bank)))
  576.     {
  577.         check = 0;
  578.         if(Acc!=pAcc) continue;
  579.         else
  580.         {
  581.             int i,j;
  582.             for(i=0,j=0;npass[i]!='\0'||pass[j]!='\0';++i,++j)
  583.             {
  584.                 if(pass[j]!=npass[i])
  585.                 {
  586.                     check = 0;
  587.                     break;
  588.                 }
  589.                 else check = 1;
  590.             }
  591.         }
  592.         if(check == 1)
  593.         {
  594.             break;
  595.         }
  596.      }
  597.      log.close();
  598.      if(check == 1)
  599.      {
  600.          cout<<"\n\nLogin Successful.";
  601.          getch();
  602.  
  603.          task(Acc);
  604.      }
  605.      else
  606.      {
  607.          --c;
  608.          if(c>0)
  609.          {
  610.          cout<<"\nWrong Password. Try again";
  611.          getch();
  612.          goto PASSINPUT;
  613.          }
  614.          else
  615.          {
  616.              cout<<"\nYou entered wrong pass 3 times.";
  617.              getch();
  618.         }
  619.      }
  620. }
  621. void bank::Search()
  622. {
  623.     START:
  624.     system("cls");
  625.     cout<<"Search : \n\n1. Account Number\n\n2. Name\n\n3. Address\n\n4. Go Back\n\n\n...";
  626.     int a;
  627.     cin>>a;
  628.     if(a==1)
  629.     {
  630.         ifstream file;
  631.         file.open("Bank.dat",ios::binary);
  632.         cout<<"\n\nEnter Account Number : ";
  633.         long Acc;
  634.         cin>>Acc;
  635.         file.seekg(0);
  636.         int found = 0;
  637.         while(file.read((char*)this,sizeof(bank)))
  638.         {
  639.             found = 0;
  640.             if(pAcc == Acc)
  641.             {
  642.                 Show();
  643.                 found = 1;
  644.                 getch();
  645.                 break;
  646.             }
  647.         }
  648.         if(found == 0)
  649.         {
  650.             cout<<"\n\nNo data found.";
  651.             getch();
  652.         }
  653.         file.close();
  654.         goto START;
  655.     }
  656.     if(a==2)
  657.     {
  658.         ifstream file;
  659.         file.open("Bank.dat",ios::binary);
  660.         cout<<"\nEnter Name : ";
  661.         char Name[30];
  662.         fflush(stdin);
  663.         gets(Name);
  664.         int i,j;
  665.         int found = 0;
  666.         int ffound = 0;
  667.         file.seekg(0);
  668.         while(file.read((char *)this,sizeof(bank)))
  669.         {
  670.             found = 0;
  671.             for(i=0,j=0;Name[i]!='\0'&& pName[j]!='\0';)
  672.             {
  673.                 if(toupper(Name[i])==toupper(pName[j]))
  674.                 {
  675.                     ++i;
  676.                     ++j;
  677.                     found = 1;
  678.                     ffound = 1;
  679.                 }
  680.                 else
  681.                 {
  682.                     found = 0;
  683.                     ++j;
  684.                 }
  685.             }
  686.             if (found == 1)
  687.             {
  688.                 Show();
  689.                 getch();
  690.             }
  691.         }
  692.         if(ffound == 0)
  693.         {
  694.             cout<<"\nNo data found.";
  695.             getch();
  696.         }
  697.         file.close();
  698.         goto START;
  699.  
  700.     }
  701.     if(a==3)
  702.     {
  703.         ifstream file;
  704.         file.open("Bank.dat",ios::binary);
  705.         cout<<"\nEnter Address : ";
  706.         char Addr[30];
  707.         fflush(stdin);
  708.         gets(Addr);
  709.         int i,j;
  710.         int found = 0;
  711.         int ffound = 0;
  712.         file.seekg(0);
  713.         while(file.read((char *)this,sizeof(bank)))
  714.         {
  715.             found = 0;
  716.             for(i=0,j=0;Addr[i]!='\0'&& pAddr[j]!='\0';)
  717.             {
  718.                 if(toupper(Addr[i])==toupper(pAddr[j]))
  719.                 {
  720.                     ++i;
  721.                     ++j;
  722.                     found = 1;
  723.                     ffound = 1;
  724.                 }
  725.                 else
  726.                 {
  727.                     found = 0;
  728.                     ++j;
  729.                 }
  730.             }
  731.             if (found == 1)
  732.             {
  733.                 Show();
  734.                 getch();
  735.             }
  736.         }
  737.         if(ffound == 0)
  738.         {
  739.             cout<<"\nNo data found.";
  740.             getch();
  741.         }
  742.         file.close();
  743.         goto START;
  744.     }
  745.  
  746. }
  747. void bank::Show()
  748. {
  749.     cout<<"\n------------------------------------------------------------------\n";
  750.     cout<<"\nAccount Number : "<<pAcc;
  751.     cout<<"\nName : "<<pName;
  752.     cout<<"\nAddress : "<<pAddr;
  753.     cout<<"\nMobile : "<<pMobile;
  754. }
  755. void bank::NewAccount()
  756. {
  757.     char Name[30];
  758.     unsigned long long Mobile;
  759.     long Acc;
  760.     char Add[200];
  761.     system("cls");
  762.     cout<<"\nEnter Name : ";
  763.     fflush(stdin);
  764.     gets(Name);
  765.     cout<<"\nAddress : ";
  766.     fflush(stdin);
  767.     gets(Add);
  768.     cout<<"\nMobile Number : ";
  769.     cin>>Mobile;
  770.     srand(time(NULL));
  771.     ifstream temp;
  772.     temp.open("Bank.dat",ios::binary);
  773.     ACCNO:
  774.     temp.seekg(0);
  775.     Acc = rand() % 11999 + 900000;
  776.     int f=0;
  777.     while(temp.read((char *)this,sizeof(bank)))
  778.     {
  779.         if(Acc == pAcc)
  780.         {
  781.             f=1;
  782.             break;
  783.         }
  784.     }
  785.     if(f==1)
  786.     {
  787.         goto ACCNO;
  788.     }
  789.     temp.close();
  790.     cout<<"\nYour Account Number is (Remember it): "<<pAcc;
  791.     start:
  792.     system("cls");
  793.     cout<<"\nEnter Name : "<<Name<<"\n\nAddress : "<<Add<<"\n\nMobile Number : "<<Mobile<<"\n\nYour Account Number is (Remember it): "<<Acc;
  794.     cout<<"\n\nEnter Password : ";
  795.     char a;
  796.     int i=0;
  797.     for(i;;)
  798.     {
  799.        a=getch();
  800.        if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
  801.         //check if a is numeric or alphabet
  802.         {
  803.             pass[i]=a;//stores a in pass
  804.             ++i;
  805.             cout<<"*";
  806.         }
  807.         if(a=='\b'&&i>=1)//if user typed backspace
  808.         //i should be greater than 1.
  809.         {
  810.             cout<<"\b \b";//rub the character behind the cursor.
  811.             --i;
  812.         }
  813.         if(a=='\r')//if enter is pressed
  814.         {
  815.             pass[i]='\0';//null means end of string.
  816.             break;//break the loop
  817.         }
  818.     }
  819.     if (i<=5)
  820.     {
  821.         cout<<"\nMinimum 6 digits needed.";
  822.         getch();
  823.         goto start;
  824.     }
  825.  
  826.     ofstream file;
  827.     file.open("Bank.dat",ios::binary|ios::app);
  828.     strcpy(pName,Name);
  829.     strcpy(pAddr,Add);
  830.     pAcc = Acc;
  831.     pMobile = Mobile;
  832.     balance = 5000;
  833.     for(i=0;i<100;++i)
  834.         ltran[i][0]='\0';
  835.     file.write((char *)this,sizeof(bank));
  836.     file.close();
  837.     cout<<"\n\nAccount Successfully Created.";
  838.     getch();
  839. }
  840.  
  841. int main()
  842. {
  843.     START:
  844.     system("cls");
  845.     cout<<"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=MAIN_MENU=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n";
  846.     cout<<"\n1. Login\n\n2. Open New Account\n\n3. View All Data\n\n4. Search\n\n5. Exit\n\n...";
  847.     int a;
  848.     cin>>a;
  849.     if(a==5)
  850.     {
  851.         exit(0);
  852.     }
  853.     bank b;
  854.     if(a==4)
  855.     {
  856.         b.Search();
  857.         goto START;
  858.     }
  859.     if(a==3)
  860.     {
  861.         ifstream f;
  862.         f.open("Bank.dat",ios::binary);
  863.         f.seekg(0);
  864.         int found = 0;
  865.         while(f.read((char*)&b,sizeof(b)))
  866.         {
  867.             b.Show();
  868.             getch();
  869.             found = 1;
  870.         }
  871.         if(found == 0)
  872.         {
  873.              cout<<"\nNo data found.";
  874.              getch();
  875.         }
  876.         f.close();
  877.         goto START;
  878.     }
  879.     if(a==2)
  880.     {
  881.         b.NewAccount();
  882.         a=1;
  883.     }
  884.     if(a==1)
  885.     {
  886.         b.Login();
  887.         goto START;
  888.     }
  889.     return 1;
  890. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement