Advertisement
apl-mhd

Bappy sir project

Apr 29th, 2017
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. #include <stdlib.h>
  6. #include <map>
  7. #include <time.h>
  8. #include <cstdlib>
  9. #define clear()  system("@cls||clear");
  10. using namespace std;
  11.  
  12. void createAccount();
  13. void updateInfo();
  14. void displayAll();
  15. void transaction();
  16. void removeAC();
  17. void existingAccount();
  18.  
  19. void mTotext(int tk){
  20.     int coin[5] = {10000000,100000,1000,100,0};
  21.  
  22.      map<int, string>moneyText;
  23.      moneyText[0] = "";
  24.      moneyText[1]  ="One";  moneyText[2] ="Two";
  25.      moneyText[3] ="Three";  moneyText[4] ="Four";
  26.      moneyText[5] ="Five";  moneyText[6] ="Six";
  27.      moneyText[7] ="Seven"; moneyText[8] ="Eight";
  28.      moneyText[9] ="Nine";
  29.  
  30.     moneyText[10] ="Ten"; moneyText[14] ="Fourteen";
  31.      moneyText[11] ="Eleven"; moneyText[15] ="Fifteen";
  32.      moneyText[12] ="Tweleve"; moneyText[16] ="Sixteen";
  33.      moneyText[13] ="Thirteen"; moneyText[17] ="Seventeen";
  34.      moneyText[18] ="Eighteen";   moneyText[19] ="Nineteen";
  35.  
  36.      moneyText[20] ="Twenty"; moneyText[30] ="Thirty";
  37.      moneyText[40] ="Fourty";  moneyText[50] ="Fifty";
  38.      moneyText[60] ="Sixty";  moneyText[70] ="Seventy";
  39.      moneyText[80] ="Eighty";  moneyText[90] ="Ninety";
  40.      moneyText[100] ="Houndred";
  41.  
  42.       moneyText[1000] ="Thousand"; moneyText[100000] ="Lakh";
  43.       moneyText[10000000] ="Crore";
  44.  
  45.     int  i = 0,index=0,reminder;
  46.     int money[10] = {0};
  47.  
  48.  
  49.  
  50.     while( i != 5){
  51.  
  52.         if(coin[i] <=tk){ /* checking tk*/
  53.             if(i==4){ /*if tk less than 100*/
  54.                 money[index]=tk;/*push  tk*/
  55.                 i++;
  56.                 }
  57.         else{
  58.             reminder = tk / coin[i];
  59.             money[index] = reminder; /*push how many times ocurs same tk*/
  60.             money[index+1] = coin[i]; /*push tk*/
  61.  
  62.             tk = tk % coin[i]; /*reminder amount*/
  63.             i++;
  64.             index+=2;
  65.     } /*end else*/
  66.  
  67.     }
  68.  
  69.     else
  70.         i++;
  71.  
  72. }/*end if*/
  73.  
  74.  
  75.     int  tenth, oneth;
  76.     for(i=0; i<=index; i++){
  77.             if(money[0] ==0){
  78.                 cout<<"Zerro"<<" ";
  79.                 break;
  80.             }
  81.  
  82.         if(money[i]> 20){ /* if money is greater than 20*/
  83.  
  84.             tenth = (money[i] /10) *10;
  85.             oneth = money[i] % 10;
  86.             cout<<moneyText[tenth]<<" "<<moneyText[oneth]<<" ";
  87.         }
  88.     else
  89.         cout<<moneyText[money[i]]<<" ";
  90.  
  91.         }
  92.  
  93.     cout<<"Tk";
  94.  
  95.     }
  96. void delay(unsigned int mseconds)
  97. {
  98.     clock_t goal = mseconds + clock();
  99.     while (goal > clock());
  100. }
  101.  
  102. bool exist(char id[100]){ /*vheck acount exist or not*/
  103.     FILE *outFile;
  104.     int count =0;
  105.     char name[100];
  106.     outFile = fopen("infile.txt", "r");
  107.     while((fscanf(outFile, "%s", name)) !=EOF){
  108.  
  109.         if(strcmp(name, id)==0 && count==0){
  110.  
  111.             fclose(outFile);
  112.             return true;
  113.         }
  114.         count++;
  115.         if(count == 8)
  116.             count=0;
  117.  
  118.     }
  119.  
  120.     fclose(outFile);
  121.  
  122.     return false;
  123. }
  124.  
  125. void menu(){ /*main menu*/
  126.  
  127.     clear();
  128.     int x;
  129.     cout<<"\n\t\t\tCUSTOMER ACCOUNT BANKINGMANAGEMENT SYSTEM\n";
  130.     printf("\n\n\t\t\t %c%c%c%c WELCOME TO THE MAIN MENU %c%c%c%c\n",178,178,178,178,178,178,178,178);
  131.  
  132.     cout<<"\n\t\t\t1.Create new account\n";
  133.     cout<<"\t\t\t2.Update information of existing account\n";
  134.  
  135.     cout<<"\t\t\t3.For transaction\n";
  136.     cout<<"\t\t\t4.Check the details of existing account\n";
  137.  
  138.     cout<<"\t\t\t5.Removing existing account\n";
  139.     cout<<"\t\t\t6.View customers's  list\n";
  140.  
  141.     cout<<"\t\t\t7.Exit\n";
  142.     cout<<"\n\n\t\t\tEnter Your chosice:";
  143.     cin>>x;
  144.     if(x==1) createAccount();
  145.     if(x==2) updateInfo();
  146.     if(x==3) transaction();
  147.     if(x==4) existingAccount();
  148.     if(x==5) removeAC();
  149.     if(x==6) displayAll();
  150.     if(x==7) exit(0);
  151.     clear();
  152.         cout<<"Invalid Input:\n";
  153.         menu();
  154. }
  155.  
  156.  
  157.  
  158. void logIn(){/*loging section*/
  159.  
  160.     int pass, x;
  161.     cout<<"\n\n\t\t\tEnter the password to login:";
  162.     cin>>pass;
  163.     if(pass != 1234){
  164.     clear();
  165.     cout<<"\n\n\n\t\t\tWrong Password\n";
  166.     cout<<"\n\n\t\tEnter 1 to try again and 0 to exit:";
  167.         cin>>x;
  168.         if(x==1){
  169.             clear();
  170.         logIn();
  171.  
  172.     }
  173.         else
  174.               exit(0);
  175. }
  176.     else{
  177.         clear();
  178.         cout<<"\n\n\n\n\t\t\t\tPassword Match!";
  179.         cout<<"\n\t\t\t\tLogin";
  180.         for(int i=0; i<10; i++){
  181.         delay(200);
  182.         cout<<".";
  183.         }
  184.         menu();
  185. }
  186.         return;
  187.     }
  188.  
  189. int main(int argc, char **argv)
  190.  
  191. {
  192.     logIn(); /*if don not match then recursivly call login() function*/
  193.  
  194.     return 0;
  195. }
  196.  
  197. void menuOrexit(int choice){ /*bakt to main menu*/
  198.     int x;
  199.     cout<<"\n\t\tEnter 1 go to the main menu and 0 to exit:";
  200.     cin>>x;
  201.     if(x==1){
  202.     clear();
  203.         menu();
  204.     }
  205.     else if(x==0){
  206.         exit(0);
  207.         }
  208.  
  209.     else{
  210.  
  211.         clear();
  212.         cout<<"invalid input";
  213.         menuOrexit(choice); /*if input invalid then menuOrexit(choice); function call again*/
  214.         }
  215.  
  216.  
  217. }
  218.  
  219.  
  220. void zero1two(int x, int choice){ /*gotot try again, exit or return to main menu*/
  221.  
  222.     cout<<"\n\t\tEnter 0 to try again, 1 to return main menu and 2 to exit:";
  223.     cin>>x;
  224.     if(x==1){
  225.     //clear();
  226.         menu();
  227.     }
  228.     else if(x==0){
  229.         if(choice == 21) updateInfo();
  230.         if(choice == 3) transaction();
  231.         if(choice == 5) removeAC();
  232.         if(choice == 6) updateInfo();
  233.  
  234.         }
  235.     else if(x==2)
  236.         exit(0);
  237.  
  238.     else{
  239.  
  240.         clear();
  241.         cout<<"invalid input";
  242.         menuOrexit(choice);
  243.         }
  244.  
  245.  
  246. }
  247.  
  248.  
  249. void createAccount(){ /*create account*/
  250.  
  251.     string tDate;
  252.     char name[100];
  253.     //char email[100];
  254.     char address[100];
  255.     char birthDay[100];
  256.     char phone[100];
  257.     char acountNumber[100];
  258.     int nid;
  259.     int age;
  260.     int deposit;
  261.  
  262.     FILE *inFile;
  263.  
  264.     inFile = fopen("infile.txt", "a+");
  265.  
  266.     clear();
  267.         printf("\t\t\t %c%c%c%c Add record %c%c%c%c\n\n",178,178,178,178,178,178,178,178);
  268.  
  269.  
  270.     cout<<"Enter today's date(mm/dd/yyyy):";
  271.     cin>>tDate;
  272.  
  273.     cout<<"\nEnter the acount number:";
  274.     scanf("%s",acountNumber);
  275.     if(exist(acountNumber) == true ){ /*check acount exist or not*/
  276.         clear();
  277.         cout<<"\n\n\t\tAccount number  already in used try again:";
  278.         delay(1700);
  279.         createAccount(); /*if id invalid then function call again*/
  280.         }
  281.  
  282.  
  283.     cout<<"\nEnter the name:";
  284.     scanf("%s", name);
  285.  
  286.     cout<<"\nEnter the date of birth(mm/dd/yyyy):";
  287.     scanf("%s", birthDay);
  288.  
  289.     cout<<"\nEnter the age:";
  290.     scanf("%d", &age);
  291.  
  292.     cout<<"\nEnter the address:";
  293.     scanf("%s", address);
  294.  
  295.     cout<<"\nEnter the NID number:";
  296.     scanf("%d", &nid);
  297.  
  298.     cout<<"\nEnter the phone number:";
  299.     scanf("%s", phone);
  300.  
  301.  
  302.     cout<<"\nEnter the amount to deposit:";
  303.     scanf("%d", &deposit);
  304.  
  305.  
  306.     fprintf(inFile, "%s %s %s %d %s %d %s %d\n", acountNumber, name,
  307.      birthDay, age, address,nid,phone,deposit);
  308.  
  309.      fclose(inFile);
  310.      cout<<"\nAccount Created successfully\n";
  311.  
  312.     menuOrexit(10);
  313.  
  314.     }
  315.  
  316. void updtPhoneAdd(char id[]){
  317.     clear();
  318.     FILE *outFile,*copyFile;
  319.     char name[100];
  320.     char updt[100];
  321.     int count=0, flag=1,locate, x;
  322.     outFile = fopen("infile.txt", "r");
  323.     copyFile = fopen("copy.txt", "w");
  324.  
  325.     cout<<"Which  information do you want to change\n\n";
  326.     cout<<"1. Address:\n";
  327.     cout<<"2. Phone:\n";
  328.     cout<<"\nEnter your choice(1 for address and 2 for phone):";
  329.     cin>>x;
  330.  
  331.     if(x!=1 && x!=2){
  332.     //cout<<x<<endl;
  333.             updtPhoneAdd(id);
  334.     }
  335.     else{
  336.     if(x==1){
  337.     clear();
  338.         cout<<"\n\n\n\t\tEnter the new address:";
  339.         scanf("%s",updt);
  340.         locate=4;
  341.     }
  342.      if(x==2){
  343.          clear();
  344.         cout<<"\n\n\n\t\tEnter the new phone:";
  345.         scanf("%s",updt);
  346.         locate=6;
  347.  
  348.         }
  349.  
  350.  
  351.     while((fscanf(outFile, "%s", name)) !=EOF){
  352.  
  353.  
  354.         if(strcmp(name, id)==0 && count==0){
  355.             flag =0;
  356.             //cout<<"yes";
  357.         }
  358.         if(flag == 0 &&count == locate)
  359.  
  360.             fprintf(copyFile, "%s ", updt);
  361.         else
  362.  
  363.             fprintf(copyFile, "%s ", name);
  364.  
  365.         if(count == 7)
  366.             fprintf(copyFile, "%c", '\n');
  367.         count++;
  368.         if(count == 8){
  369.  
  370.             flag =1;
  371.             count=0;
  372.  
  373.         }
  374.  
  375.  
  376.     }
  377.  
  378.     fclose(outFile);
  379.     fclose(copyFile);
  380.     remove("infile.txt");
  381.     rename("copy.txt", "infile.txt");
  382.  
  383.     clear();
  384.     cout<<"\n\t\t\t\tChanged saved!\n";
  385.  
  386.  
  387.     zero1two(0,6);
  388.     //menuOrexit(0);
  389.  
  390. }
  391.  
  392. }
  393.  
  394.  
  395. void updateInfo(){/*check id*/
  396.  
  397.     clear();
  398.     cout<<"\n\nEnter the account NO. of customer whose information you want to change:";
  399.     char id[100];
  400.     scanf("%s", id);
  401.     if(exist(id) !=true){
  402.         clear();
  403.         cout<<"\t\t\t\ninvalid id\n";
  404.         zero1two(0,21);
  405.  
  406.  
  407.         }
  408.     else
  409.  
  410.     updtPhoneAdd(id);/*if id found then call update function */
  411. }
  412.  
  413. /*
  414. #########################################################
  415. #           Display all account        #
  416. #########################################################
  417. */
  418. void displayAll(){
  419.     clear();
  420.     FILE  *fileRead;
  421.     fileRead = fopen("infile.txt", "r");
  422.  
  423.     char ch[100];
  424.     int count=0;
  425.     printf("ACC. NO| \t Name| \t\t Adddress| \t Phone|\n");
  426.     printf("___________________________________________________________\n\n");
  427.  
  428.     while((fscanf(fileRead,"%s", ch)) !=EOF){
  429.  
  430.         if(count == 0 || count == 1 || count ==4 || count == 6)
  431.             cout<<ch<<"\t\t";
  432.  
  433.         count++;
  434.         if(count== 8){
  435.             cout<<endl;
  436.             count=0;
  437.         }
  438.  
  439. }
  440. printf("___________________________________________________________\n\n");
  441.  
  442. fclose(fileRead);
  443.  
  444.     menuOrexit(0);
  445.  
  446. }
  447.  
  448.  
  449. /*
  450. #########################################################
  451. #            Existing Account Removing Part           #
  452. #########################################################
  453. */
  454. void removeAC(){
  455. clear();
  456.  
  457. int count=0, flag=1;
  458. char name[100], id[100];
  459. char ch='\n';
  460.  
  461. cout<<"\n\n\t\tEnter the account NO. of the customer you want to delete:";
  462.     scanf("%s", id);
  463.  
  464.     if(exist(id)){ /*checking acount exist or not*/
  465.     FILE *orginalFile,*copyFile;
  466.  
  467.     orginalFile = fopen("infile.txt", "r");
  468.     copyFile = fopen("copy.txt", "w");
  469.  
  470.     while((fscanf(orginalFile, "%s", name)) !=EOF){
  471.  
  472.  
  473.         if(strcmp(name, id)==0 && count==0){
  474.             flag =0;
  475.  
  476.         }
  477.         if(flag !=0){
  478.             fprintf(copyFile, "%s ", name);
  479.             }
  480.         if(count == 7 && flag !=0)
  481.             fprintf(copyFile, "%c", '\n');
  482.  
  483.         count++;
  484.         if(count == 8){
  485.  
  486.             flag =1;
  487.             count=0;
  488.  
  489.         }
  490.         //1 Orko 20/12/1994 20 Dhaka 1234 01710453438 120
  491. }
  492.  
  493.     fclose(orginalFile);
  494.     fclose(copyFile);
  495.     remove("infile.txt");
  496.     rename("copy.txt", "infile.txt");
  497. }
  498. else{
  499.  
  500.     clear();
  501.     cout<<"\n\n\t\t\tRecord not found.\n";
  502.     zero1two(0,5);/*if fail then return main main or exit call again*/
  503.  
  504. }
  505.  
  506.     clear();
  507.     cout<<"\n\n\t\tRecord deleted successfully!\n";
  508.     menuOrexit(0);
  509.  
  510.  
  511. }
  512.  
  513. void transaction(){
  514.     clear();
  515.     char id[100];
  516.  
  517.  
  518.     char name[100];
  519.     int count=0, flag=1,choice,deposit,x;
  520.  
  521.     cout<<"\n\n\t\t\tEnter the account number of customer:";
  522.     scanf("%s", id);
  523.  
  524.     if(exist(id) == true){
  525.         clear();
  526.     cout<<"Do you want to\n"<<endl<<"1. Deposit?"<<endl<<"2. Withdraw\n"<<endl;
  527.  
  528.     cout<<"Enter your choice(1 for deposit 2 for withdraw):";
  529.     cin>>choice;
  530.     if(choice ==1 ){
  531.         clear();
  532.          cout<<"\n\n\t\tEnter the amount you want to deposit:";
  533.           cin>>deposit;
  534.     }
  535.     else if (choice ==2){
  536.         clear();
  537.         cout<<"\n\n\t\tEnter the amount you want to withdraw:";
  538.           cin>>deposit;
  539.     }
  540.  
  541.     FILE *orginalFile,*copyFile;
  542.     orginalFile = fopen("infile.txt", "r");
  543.     copyFile = fopen("copy.txt", "w");
  544.  
  545.     while((fscanf(orginalFile, "%s", name)) !=EOF){
  546.  
  547.  
  548.         if(strcmp(name, id)==0 && count==0){
  549.             flag =0;
  550.             //cout<<"yes";
  551.         }
  552.         if(flag == 0 &&count ==7 ){
  553.             //printf("%s",name);
  554.             if(choice == 1)
  555.              x = atoi(name)+deposit;
  556.              else
  557.               x = atoi(name)- deposit;
  558.             fprintf(copyFile, "%d ", x);
  559.  
  560.             }
  561.         else
  562.  
  563.             fprintf(copyFile, "%s ", name);
  564.  
  565.         if(count == 7)
  566.             fprintf(copyFile, "%c", '\n');
  567.         count++;
  568.         if(count == 8){
  569.  
  570.             flag =1;
  571.             count=0;
  572.  
  573.         }
  574.  
  575.  
  576.     }
  577.  
  578.  
  579.     fclose(orginalFile);
  580.     fclose(copyFile);
  581.     remove("infile.txt");
  582.     rename("copy.txt", "infile.txt");
  583.     clear();
  584.     cout<<"\n\n\t\t\t\tSuccess!\n";
  585.     menuOrexit(0);/*if success then menu function call again*/
  586.     //transaction();
  587. }
  588.  
  589. else{
  590.     clear();
  591.     cout<<"Record not found!\n";
  592.     zero1two(0,3);/*if naot found */
  593.  
  594. }
  595.  
  596. }
  597.  
  598.  
  599. void existingAccount(){
  600.  
  601. clear();
  602. int count=0, flag=1,i=0;
  603. char name[100], id[100];
  604.     cout<<"\n\n\t\t\t\tEnter the account number:";
  605.     scanf("%s", id);
  606.  
  607.     if(exist(id)){
  608.             clear();
  609.     string info[10] =  {"Account NO.:", "Name:", "DOB:", "Age:",
  610.         "Address:","NID No:","Phone NO:", "Amount deposited:BDT "};
  611.     FILE *outFile;
  612.  
  613.     outFile = fopen("infile.txt", "r");
  614.  
  615.     while((fscanf(outFile, "%s", name)) !=EOF){
  616.  
  617.         if(strcmp(name, id)==0 && count==0)
  618.             flag =0;
  619.             if(flag == 0 &&count<8 ){
  620.  
  621.             //printf("%s\n",name);
  622.                 if(i == 7){
  623.                     int m = atoi(name);
  624.                     cout<<info[i++];
  625.                     mTotext(m);
  626.                     cout<<"\n";
  627.                 }
  628.                 else
  629.                     cout<<info[i++]<<name<<endl;
  630.                     count++;
  631.             }
  632.  
  633.         else {
  634.         count++;
  635.         if(count == 8){
  636.  
  637.             flag =1;
  638.             count=0;
  639.  
  640.         }
  641. }
  642.     }
  643.  
  644.     fclose(outFile);
  645. }
  646. else{
  647.     clear();
  648.     cout<<"Record not found\n";
  649. }
  650.     menuOrexit(0); /*press 1 for main menu 0 for exit*/
  651.  
  652. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement