Advertisement
Guest User

mp

a guest
Mar 12th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.59 KB | None | 0 0
  1. /**********************************************************************************************************************
  2. This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts
  3. learned. I have constructed the functions and their respective algorithms and corresponding code by myself. The program
  4. was run, tested, and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise
  5. plagiarized the work of other students and/or persons.
  6. Brent Aldwinne P. Lim, 11609281
  7. **********************************************************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #define MAX_CART 100
  13.  
  14. typedef char string15[16];
  15. typedef char string20[21];
  16. typedef char string50[51];
  17. typedef char string8[9];
  18.  
  19. typedef struct{
  20.     string20 first;
  21.     string20 middle;
  22.     string20 last;
  23. }nameType;
  24.  
  25. typedef struct{
  26.     nameType name;
  27.     string50 address;
  28. }userInfoType;
  29.  
  30. typedef struct{
  31.     string8 code;
  32.     int qty;
  33. }prodBoughtType;
  34. typedef prodBoughtType arrBought[MAX_CART];
  35.  
  36. struct userTag{
  37.     string15 username;
  38.     string15 password;
  39.     userInfoType info;
  40.     char type;
  41.     float creditLimit;
  42.     float outstanding;
  43.     arrBought cart;
  44.     int nItems;
  45.     int locked;
  46.     int chk;
  47.     struct userTag *pNext;
  48. };
  49. typedef struct userTag userType;
  50. typedef userType *ptrUser;
  51.  
  52. struct userProduct { //linked list for the products
  53.     string15 category;
  54.     string15 supplier;
  55.     string15 product;
  56.     string8 pCode;
  57.     int qAvail;
  58.     int qSold;
  59.     float purchasePrice;
  60.     float salePrice;
  61.     float discountRate;
  62.     struct userProduct *pNext;
  63. };
  64.  
  65. void addNewStock(userProduct *pProd,userProduct *pNew){
  66.     userProduct pTemp;
  67.     pTemp=pProd;
  68.     int choice=01
  69.     char cDump;
  70.      
  71.     do{
  72.         printf("Enter Category:");
  73.         fgets(pNew->category, 16, stdin);
  74.         printf("You entered %s Category\n",pNew->category);
  75.        
  76.         printf("Input supplier Name:");
  77.         scanf("%s%c",pProd->supplier,&cDump);
  78.        
  79.         printf("Input product name:");
  80.         scanf("%s%c",pNew->product,&cDump);
  81.        
  82.         printf("Enter Available Product Quantity: ");
  83.         canf("%d%c", pNew->qAvail, &cDump);
  84.    
  85.         printf("Input Price of the Product: ");
  86.         scanf("%f%c",pNew->purchasePrice, &cDump);
  87.    
  88.         printf("Input the Unit Selling Price of the product: ");
  89.         scanf("%f%c", pNew->salePrice, &cDump);
  90.    
  91.         printf("Input the Discount Rate of the product: ");
  92.         scanf("%f%c", pNew->discountRate, &cDump);
  93.        
  94.         pNew->qSold = 0;
  95.        
  96.     printf("1.Add new stock?\n")
  97.     printf("2.Go back to menu?? \n");
  98.     scanf("%d",&choice);
  99.     if(n!=choice || n!=choice )
  100.         printf("Invalid Input... Returning you to Manage Stocks Menu");
  101.  
  102.     }while(choice!=0);
  103. }          
  104. }
  105.  
  106. void viewAllStocks(){
  107.    
  108. }
  109.  
  110. void viewCategory(){
  111.    
  112. }
  113.  
  114. void viewToReorder(){
  115.    
  116. }
  117.  
  118. void modifyStockInfo(){
  119.    
  120. }
  121.  
  122. void restock(){
  123.    
  124. }
  125.  
  126. void saveInventory(){
  127.    
  128. }
  129.  
  130. //Function Name: manageStocks
  131. //Function Required Input Parameters: option
  132. //Function Expected Return Data: N/A
  133. //Function Description and or Algorithim: To have access on the stocks of the progam
  134. void manageStocks(userProduct *pProd,userProduct *pNew){
  135.     int choice;
  136.     int end=0;
  137.     printf("     MANAGE STOCKS MENU  \n");
  138.     printf("1.Add New Stock");
  139.     printf("2.View All Stocks");
  140.     printf("3.View Stocks by Category");
  141.     printf("4.View Stocks to Reorder");
  142.     printf("5.Modify Stock Info");
  143.     printf("6.Restock");
  144.     printf("7.Save Inventory");
  145.     printf("8.Back to Admin Menu");
  146.    
  147.     do{
  148.         switch(choice){
  149.         case 1:addNewStock(pProd,pNew);
  150.               break;
  151.         case 2:viewAllStocks();
  152.               break;
  153.         case 3:viewCategory();
  154.               break;
  155.         case 4:viewToReorder();
  156.               break;
  157.         case 5:modifyStockInfo();
  158.               break;
  159.         case 6:restock();
  160.               break;
  161.         case 7:saveInventory();
  162.               break;
  163.         case 8:end=0;
  164.         }
  165.     }while(end!=0);
  166.    
  167. }
  168. //Function Name: manageAccounts
  169. //Function Required Input Parameters: choice
  170. //Function Expected Return Data: N/A
  171. //Function Description and or Algorithim: To allow user to manage accounts of the kiosk
  172. void manageAccounts(ptrUser pUser){
  173.     int choice,end=1;
  174.     ptrUser *pTemp=NULL;
  175.  
  176.     do
  177.     {      
  178.         printf("   MANAGE ACCOUNTS MENU   \n");
  179.         printf("Enter choice:");
  180.         printf("1.View Locked Accounts\n");
  181.         printf("2.Unlock Specific Account\n");
  182.         printf("3.Unlock All Locked Accounts\n");
  183.         printf("4.View Accounts with Outstanding Balance\n");
  184.         printf("5.Return to Administrator Menu\n");
  185.        
  186.         printf("Enter choice:");
  187.         scanf("%d", &choice);
  188.    
  189.         switch (choice)
  190.         {
  191.             case 1: viewLocked(pUser);
  192.                     break;
  193.             case 2: unlockAccount(pUser);
  194.                     break;
  195.             case 3: unlockAll(pUser);
  196.                     break;
  197.             case 4: viewBal(pUser);
  198.                     break;
  199.             case 5: end=0;
  200.         }
  201.     } while (end);
  202. }
  203. //Function Name: viewLocked
  204. //Function Required Input Parameters: N/A
  205. //Function Expected Return Data: N/A
  206. //Function Description and or Algorithim: To view accounts that are locked
  207. void viewLocked (ptrUser *pUser){
  208.     ptrUser *pTemp=NULL;
  209.    
  210.     pTemp=pUser;
  211.    
  212.     printf("View Locked Accounts:\n");
  213.    
  214.     do
  215.     {
  216.         if ((*pTemp).locked==1)
  217.             printf("Account: %s\n", ctr, pTemp->username);
  218.         pTemp=pTemp->pNext;    
  219.     } while (pTemp!=NULL);
  220.    
  221. }
  222. //Function Name: unlockAccount
  223. //Function Required Input Parameters: username of desired account
  224. //Function Expected Return Data: N/A
  225. //Function Description and or Algorithim: To unlock account
  226. void unlockAccount (ptrUser *pUser){
  227.     string15 user; 
  228.     ptrUser *pTemp=NULL;
  229.     int comp=1, choice, end=0;
  230.    
  231.     pTemp=pUser;
  232.    
  233.     printf("Unlock account: \n");
  234.    
  235.     do
  236.     {
  237.         printf("Enter username of the account you want to unlock: \n");
  238.         scanf("%s",&user);
  239.        
  240.         comp=strcmp(user, (*pTemp).username);
  241.        
  242.         do
  243.         {
  244.             if ((*pTemp).locked==1 && compare==0)
  245.             {
  246.                 (*pTemp).locked=0;
  247.                 pTemp=(*pTemp).pNext;
  248.             }
  249.         } while (pTemp!=NULL);
  250.        
  251.         printf("%s has been unlocked.\n",(*pTemp).username);
  252.         printf("Unlock another user? \n");
  253.         printf("1. Yes\n");
  254.         printf("2. No\n");
  255.         scanf("%d",&choice);
  256.        
  257.         do
  258.         {
  259.             switch (choice)
  260.             {
  261.                 case 1: end=0;
  262.                         break;
  263.                 case 2: end=1;
  264.                 default:printf("Invalid Input! Try Again!");
  265.             }
  266.         } while (choice!=1 && choice!=2);
  267.        
  268.     } while (end==0);
  269.    
  270. }
  271. //Function Name: unlockAll
  272. //Function Required Input Parameters: N/A
  273. //Function Expected Return Data: N/A
  274. //Function Description and or Algorithim: unlocks all locked accounts
  275. void unlockAll (ptrUser *pUser){
  276.     ptrUser *pTemp=NULL;
  277.    
  278.     pTemp=pUser;
  279.        
  280.     do
  281.     {
  282.         if ((*pTemp).locked==1)
  283.             (*pTemp).locked=0;
  284.         pTemp=(pTemp).pNext;   
  285.     } while (pTemp!=NULL);
  286.    
  287.     printf("All accounts are unlocked!\n");
  288. }
  289. //Function Name: viewBal
  290. //Function Required Input Parameters: N/A
  291. //Function Expected Return Data: N/A
  292. //Function Description and or Algorithim: To view accounts that have outstanding balance
  293. void viewBal (ptrUser *pUser){
  294.     ptrUser *pTemp=NULL;
  295.    
  296.     printf("View Outstanding Balance: \n");
  297.    
  298.     do
  299.     {
  300.         if ((*pTemp).outstanding <= 0.00)
  301.             printf("Sorry, outstanding balance is 0.00\n");
  302.         else if (temp->outstanding > 0.00)
  303.         {
  304.             printf("Username: %s",(*pTemp).username);
  305.             printf("Outstanding Balance is: %f\n", (*pTemp).outstanding);
  306.         }
  307.         pTemp=(*pTemp).next;
  308.        
  309.     } while (pTemp!=NULL);
  310. }
  311. //Function Name: modifyInfo
  312. //Function Required Input Parameters: option
  313. //Function Expected Return Data: N/A
  314. //Function Description and or Algorithim: allow user to choose on what to modify
  315. void modifyInfo(ptrUser pUser){
  316.     int choice;
  317.     printf("    MODIFY INFO MENU \n  ");
  318.     printf("Enter option\n");
  319.     printf("1.Change Name\n");
  320.     printf("2.Change address \n");
  321.     printf("3.Change password \n");
  322.     printf("4.Back to Shopper Menu");
  323.     scanf("%d",choice);
  324.    
  325.     switch(choice){
  326.         case 1: editName(&(*pUser).info);
  327.         case 2: editAddress(&(*pUser).info);
  328.         case 3: editPassword(pUser);
  329.     }
  330.    
  331. }
  332. //Function Name: editPassword
  333. //Function Required Input Parameters: password
  334. //Function Expected Return Data: N/A
  335. //Function Description and or Algorithim: To edit password
  336. void editName(userInfoType *pInfo){
  337.     printf("Enter the following to change name\n");
  338.    
  339.     printf("First name:");
  340.     fgets(pInfo -> name.first, 21, stdin);
  341.     printf("Middle name:");
  342.     fgets(pInfo -> name.middle, 21, stdin);
  343.     printf("Last name:");
  344.     fgets(pInfo -> name.last, 21, stdin);
  345.    
  346.     (*pInfo).name.first[strlen((*pInfo).name.first)-1] = '\0';
  347.     pInfo -> name.middle[strlen(pInfo -> name.middle)-1] = '\0';
  348.     pInfo -> name.last[strlen(pInfo -> name.last)-1] = '\0';
  349.    
  350.     printf("Edit successful!");
  351.     printf("Name: %s, %s %s\n",(*pInfo).name.last, pInfo -> name.first, pInfo -> name.middle);
  352.     system("cls");
  353. }
  354. //Function Name: editAddress
  355. //Function Required Input Parameters: address
  356. //Function Expected Return Data: N/A
  357. //Function Description and or Algorithim: To edit address
  358. void editAddress(userInfoType *pInfo){
  359.     printf("Enter to change the address address\n");
  360.     fgets((*pInfo).address,51,stdin);
  361.     (*pInfo).address[strlen((*pInfo).address)-1] = '\0';
  362.     printf("Adress: %s\n",(*pInfo).address);
  363.     system("cls");
  364. }
  365. //Function Name: editPassword
  366. //Function Required Input Parameters: password
  367. //Function Expected Return Data: N/A
  368. //Function Description and or Algorithim: To edit password
  369. void editPassword(ptrUser *pUsers){
  370.     char cDump;
  371.    
  372.     do{
  373.        printf("Enter New Password: ");
  374.        scanf("%s%c",(*pUsers).password,&cDump);
  375.     } while (strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15 || checkPword(pUsers)==0);
  376.    
  377.     printf("Password successfully changed!");
  378.     printf("Your new password is: %s \n",(*pUsers).password);
  379.     printf("%s\n", (*pUsers).password);
  380.     system("cls");
  381. }
  382. //Function Name: displayAdmin
  383. //Function Required Input Parameters: option on what admin wants to do
  384. //Function Expected Return Data: N/A
  385. //Function Description and or Algorithim: allow admin to do what the user desires with account
  386. void displayAdmin(ptrUser pUsers){
  387.     system("cls");
  388.     userProduct pProd=NULL;
  389.     userProduct pNew;
  390.     int choice,end=0;
  391.    
  392.     printf("    ADMINISTRATOR MENU  \n  ");
  393.     printf("Enter number of choice:\n");
  394.     printf("1.Manage Accounts\n");
  395.     printf("2.Manage Stocks\n");
  396.     printf("3.Prepare Delivery Report\n");
  397.     printf("4.Shutdown Kiosk\n");
  398.     printf("5.Log out \n");
  399.     scanf("%d",&choice);
  400.    
  401.     do{
  402.        switch(choice){
  403.            case 1:system("cls");
  404.                  manageAccounts(pUsers);
  405.                  break;
  406.            case 2: system("cls");
  407.                  manageStocks(pProd,pNew);
  408.                  break;
  409.            case 3:system("cls");
  410.                  printf("Preparing Delivery Report...");
  411.                  deliveryReport(pUser,pProd);
  412.                  break;
  413.            case 4: printf("Thank you! Shop with us again!");
  414.                  exit(0);
  415.                  break;
  416.            case 5:printf("You have logged out");
  417.                  end=0;
  418.            
  419.        }
  420.     }while(end);
  421. }
  422. //Function Name: displayShopper
  423. //Function Required Input Parameters: option on what the shopper wants to do
  424. //Function Expected Return Data: N/A
  425. //Function Description and or Algorithim: allows user to
  426. void displayShopper(ptrUser pUsers){
  427.     system("cls");
  428.     int choice,end=0;
  429.    
  430.     printf("    SHOPPER MENU  \n  ");
  431.     printf("Enter number of choice:\n");
  432.     printf("1.Modify User Info\n");
  433.     printf("2.Browse All Products \n");
  434.     printf("3.Browse All Products by Category\n");
  435.     printf("4.Browse Products on Sale");
  436.     printf("5.Add Item to Cart \n");
  437.     printf("6.View Items in Cart");
  438.     scanf("%d",&choice);
  439.    
  440.     do{
  441.        switch(choice){
  442.            case 1: modifyInfo(pUsers);
  443.                  break;
  444.            case 2: ;
  445.                  break;
  446.            case 3: browse
  447.                  break;
  448.            case 4:
  449.                  break;
  450.            case 5:
  451.                  break;
  452.            case 6:
  453.        }
  454.     }while(end);
  455. }
  456.  //Function Name: numUsers
  457. //Function Required Input Parameters: N/A
  458. //Function Expected Return Data: returns number of users
  459. //Function Description and or Algorithim: To count number of accounts in the system
  460. int numUsers(ptrUser pUsers){
  461.     int ctr=0;
  462.     while(pUsers != NULL){
  463.       ctr++;
  464.       pUsers = pUsers->pNext;
  465.     }
  466.     return ctr;
  467. }
  468.  
  469. //Function Name: logIn
  470. //Function Required Input Parameters: username and password. if admin,authorization code is also needed.
  471. //Function Expected Return Data: N/A
  472. //Function Description and or Algorithim: to allow users access for their account
  473.  
  474. void logIn(ptrUser pUsers){
  475.     string15 user,pword;
  476.     string8 accesscode;
  477.     system("cls");
  478.     int approve=0;
  479.     int attempts=0;
  480.     int end=1;
  481.       if((*pUsers).type == 's' || (*pUsers).type == 'S')
  482.         do {
  483.            printf("Enter Username: ");
  484.            scanf("%s",&user);
  485.            if (strcmp((*pUsers).username,user) == 0 && attempts < 3){
  486.               do{
  487.                 printf("Enter Password: ");
  488.                 scanf("%s",&pword);
  489.                 if (strcmp (pUsers->password,pword)!=0){
  490.                    printf("Try again, %d try/s left\n",3-attempts);
  491.                    attempts++;
  492.                   }
  493.                 else if (strcmp((*pUsers).password,pword) == 0)
  494.                      approve=1;
  495.                }while (attempts <= 3 && strcmp (pUsers->password,pword) !=0);
  496.             }
  497.             /*if (strcmp(pUsers->password,input)==0)
  498.                 if (user.type == 's')
  499.                     shopper(&(*pUsers));
  500.                 else if (user.type == 'A')
  501.                     administrator(&(*pUsers))
  502.             else if (attempts >= 3)*/
  503.         } while (strcmp (pUsers->username,user));
  504.         if (approve==1)
  505.             displayShopper(pUsers);
  506.    
  507.    
  508.     else if((*pUsers).type == 'a' || (*pUsers).type == 'A')
  509.          do{
  510.             printf("Enter Username: ");
  511.             scanf("%s",&user);
  512.             if (strcmp((*pUsers).username,user) == 0 && attempts < 3){
  513.                do{
  514.                   printf("Enter Password: ");
  515.                   scanf("%s",&pword);
  516.                   do{
  517.                      printf("Enter access code:");
  518.                      scanf("%s",&accesscode);
  519.                      if (strcmp (accesscode,"DLSU2017")!=0){
  520.                           printf("Try again, %d try/s remaining\n",3-attempts);
  521.                           attempts++;
  522.                        }
  523.                      else approve=1,end=0;
  524.                   } while(attempts <= 3 && strcmp(accesscode,"DLSU2017") != 0);
  525.                   if (strcmp (pUsers->password,pword)!=0){
  526.                      printf("Try again, %d try/s remaining\n",3-attempts);
  527.                      attempts++;
  528.                   }
  529.                   else if (attempts>3)
  530.                       printf("Account Locked! Back to Menu!");
  531.                       (*pUsers).locked=1;
  532.                       getch();
  533.                       end = 0;
  534.                 } while (attempts <= 3 && strcmp (pUsers->password,pword) !=0);
  535.             }  
  536.             else if(attempts>3)  
  537.                  printf("Exceeded number of attempts. Locking account. Press any keys.");
  538.             else
  539.                 printf("Try again, %d try/s remaining\n",3-attempts);
  540.                 attempts++;  
  541.          }while (strcmp ((*pUsers).username,user) && end==1);
  542.          if(approve==1)
  543.             displayAdmin(pUsers);
  544. }
  545.  
  546. ptrUser search(ptrUser pFirst, string15 username){
  547.     ptrUser pRun;
  548.    
  549.     pRun = pFirst;
  550.    
  551.     while (pRun != NULL && strcmp(username, pRun->username) != 0){
  552.         pRun = pRun->pNext;
  553.     }
  554.     return pRun;
  555. }
  556.  //Function Name: deleteNode
  557. //Function Required Input Parameters: N/A
  558. //Function Expected Return Data: N/A
  559. //Function Description and or Algorithim: To delete node
  560. void deleteNode(ptrUser *pFirst,string15 username){
  561.     ptrUser pFind, pRun;
  562.     if (pFirst == NULL)
  563.        printf("List is empty");
  564.     else{
  565.         pFind = search(*pFirst, username);
  566.         if (pFind == NULL)
  567.            printf("%s is not in the list\n",username);
  568.         else //found note to delete
  569.            if (pFind == *pFirst){
  570.               *pFirst = (*pFirst)->pNext;
  571.               free(pFind);
  572.               pFind = NULL;
  573.            }
  574.            else { //delete from middle or end
  575.               pRun = *pFirst;
  576.               while (pRun->pNext != pFind){
  577.                  pRun = pRun->pNext;
  578.               }
  579.               pRun->pNext = pFind->pNext;
  580.               free(pFind);
  581.               pFind = NULL;
  582.            }
  583.         }
  584.     }
  585.  
  586.  //Function Name: displayAllRecur & displayAll
  587. //Function Required Input Parameters: N/A
  588. //Function Expected Return Data: N/A
  589. //Function Description and or Algorithim: To display all accounts
  590. void displayAllRecur(ptrUser pUsers){
  591.     if(pUsers != NULL){
  592.         printf("%s\n",pUsers->username);
  593.         displayAllRecur(pUsers->pNext);
  594.     }
  595. }
  596.  //Function Name: freeAll
  597. //Function Required Input Parameters: N/A
  598. //Function Expected Return Data: N/A
  599. //Function Description and or Algorithim: To free allocated memory of program
  600. void freeAll(ptrUser * pFirst){
  601.     ptrUser pDel;
  602.    
  603.     while(*pFirst != NULL){
  604.      pDel = *pFirst;
  605.      *pFirst = (*pFirst)->pNext;
  606.      free(pDel);
  607.     }
  608. }
  609.  
  610. void displayAll(ptrUser pUsers){
  611.     while(pUsers != NULL){
  612.       printf("%s\n",pUsers->username);;
  613.       pUsers = pUsers->pNext;
  614.     }
  615. }
  616.  
  617. //Function Name: getUserInfo
  618. //Function Required Input Parameters: complete name and address
  619. //Function Expected Return Data: N/A
  620. //Function Description and or Algorithim: to provide information for the account of user
  621. void getUserInfo(userInfoType *pInfo){
  622.    
  623.     printf("Enter name\n");
  624.    
  625.     printf("First name:");
  626.     fgets((*pInfo).name.first,21,stdin);
  627.     printf("Middle name:");
  628.     fgets(pInfo -> name.middle,21,stdin);
  629.     printf("Last name:");
  630.     fgets(pInfo -> name.last,21,stdin);
  631.    
  632.     printf("Enter address\n");
  633.     fgets((*pInfo).address,51,stdin);
  634.    
  635.     (*pInfo).address[strlen((*pInfo).address)-1] = '\0';
  636.     (*pInfo).name.first[strlen((*pInfo).name.first)-1] = '\0';
  637.     pInfo -> name.middle[strlen(pInfo -> name.middle)-1] = '\0';
  638.     pInfo -> name.last[strlen(pInfo -> name.last)-1] = '\0';
  639.    
  640.     printf("Name: %s, %s %s\n",(*pInfo).name.last, pInfo -> name.first, pInfo -> name.middle);
  641.     printf("Adress: %s\n",pInfo->address);
  642.    
  643. }
  644. //Function Name: checkPassword
  645. //Function Required Input Parameters: N/A
  646. //Function Expected Return Data: returns 0 and 1 for the status of approval
  647. //Function Description and or Algorithim: To check if password is approved
  648. int checkPassword(userType *pUser){
  649.     int i=0;
  650.     int ctr=0;
  651.    
  652.     while(i<strlen((*pUser).password)){
  653.         if ((*pUser).password[i] < 'A' || (*pUser).password[i] > 'Z')
  654.             if ((*pUser).password[i] < 'a' || (*pUser).password[i] > 'z')
  655.               ctr++;
  656.         i++;
  657.     }
  658.    
  659.     if (ctr>0)
  660.        return 0;
  661.     else return 1;
  662. }
  663. //Function Name: checkUser
  664. //Function Required Input Parameters: N/A
  665. //Function Expected Return Data: returns 0 or 1 to check if username is taken
  666. //Function Description and or Algorithim: To know if username is used
  667. int checkUser(string15 username, string15 user){
  668.     if (strcmp(username,user)==0)
  669.        return 1;
  670.     else return 0;
  671. }
  672.  
  673. //Function Name: SignUp
  674. //Function Required Input Parameters: username and password. if admin,authorization code is also needed.
  675. //Function Expected Return Data: N/A
  676. //Function Description and or Algorithim: To create account for user
  677. void signUp(userType *pUser,userType *pUsers){
  678.     system("cls");
  679.     char cDump;
  680.     string8 access;
  681.     int check=0;
  682.     string15 temp;
  683.     do{
  684.        
  685.        printf("Enter username:");
  686.        scanf("%s",(*pUser).username); //(*pUser).username can be (pUser -> username)
  687.        //scanf("%s%c", (*pUser).username,&cDump);
  688.        if(strlen((*pUser).username) < 3 || strlen((*pUser).username) > 15)
  689.           printf("Invalid username! Try again!\n");
  690.        else strcpy((*pUser).username,temp);
  691.             (*pUser).chk = checkUser((*pUser).username,temp);
  692.             while(pUsers!=NULL){
  693.             if((*pUser).chk==0)
  694.             do{
  695.               printf("Username already taken! Try again!\n");
  696.               printf("Enter username:");
  697.               scanf("%s",(*pUser).username);
  698.               (*pUser).chk=checkUser((*pUser).username,temp);
  699.             }while((*pUser).chk == 0);
  700.             }
  701.             else printf("Username approved!");
  702.                  (*pUser).chk == 1;
  703.        
  704.     } while (strlen((*pUser).username) < 3 || strlen((*pUser).username) > 15 );
  705.    
  706.     printf("%s\n",(*pUser).username);
  707.    
  708.     do{
  709.        
  710.        printf("Enter password:");
  711.        //scanf("%s",(*pUser).password);  //(*pUser).password can be (pUser -> password)
  712.        scanf("%s%c", (*pUser).password,&cDump);
  713.        if(strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15)
  714.           do{
  715.             printf("Invalid! Try Again!");
  716.             printf("Enter password:");
  717.             scanf("%s%c", (*pUser).password,&cDump);
  718.           }while(strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15);
  719.        else printf("Password is approved!");
  720.     } while (strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15);
  721.    
  722.     printf("%s \n",(*pUser).password);
  723.    
  724.     getUserInfo(&(*pUser).info);
  725.     //getUserInfo(pUser -> info);
  726.    
  727.        printf("Account Type:\n");
  728.        printf("a or A - Administrator \n");
  729.        printf("s or S - Shopper \n");
  730.        scanf("%c%c",&(*pUser).type,&cDump);
  731.    
  732.        if((*pUser).type == 's' || (*pUser).type =='S'){
  733.           printf("Account Activation successful!\n");
  734.           (*pUser).creditLimit = 5000.00;
  735.           (*pUser).outstanding = 0.00;
  736.           (*pUser).nItems = 0;
  737.         }
  738.        else if((*pUser).type == 'a'|| (*pUser).type =='A'){
  739.             while(strcmp(access,"DLSU2017") != 0){
  740.                 printf("Admin Code:");
  741.                 scanf("%s%c",&access,&cDump);
  742.                 if(strcmp(access,"DLSU2017")==0)
  743.                     check=1;
  744.                 if(check=1)
  745.                      (*pUser).type = 'A';
  746.                      printf("Account Authentication successful!\n");
  747.                
  748.             }
  749.        }
  750.        else printf("Invalid account type. Try Again");
  751. }
  752.  
  753. int main(){
  754. /*
  755.     userType user;
  756.     userType *pUsers = NULL;
  757.     userType *pNew;
  758. */
  759.     ptrUser pUsers = NULL;
  760.     ptrUser pNew,/*pLast*/pRun,pTrail;
  761.     string15 username;
  762.     int opt;
  763.     int end = 1;
  764.     char cDump;
  765.    
  766. //Function Name: main
  767. //Function Required Input Parameters: N/A
  768. //Function Expected Return Data: N/A
  769. //Function Description and or Algorithim: Displays the options for user to choose
  770.    
  771.     do{
  772.         printf("Enter your number of option:\n\n");
  773.         printf("1:Log In \n");
  774.         printf("2:Sign Up \n");
  775.         printf("3.Delete account\n");
  776.         printf("4.Display all active accounts\n");
  777.         printf("5.Close program \n");
  778.         printf("Choice:");
  779.         scanf("%d%c",&opt,&cDump);
  780.        
  781.         switch(opt){
  782.             case 1:logIn(pNew);
  783.             case 2:pNew = malloc(sizeof(userType));
  784.                    signUp(pNew,pUsers);
  785.                    pNew -> pNext = NULL;
  786.                    if (pUsers == NULL) //first user
  787.                     pUsers = pNew; //pNew is first
  788.                     else if (strcmp (pUsers->username, pNew->username)>0){ //connect as first node
  789.                         pNew->pNext = pUsers;
  790.                         pUsers = pNew;
  791.                         }
  792.                     else { //modifying middle of the list
  793.                         pRun = pUsers ;
  794.                         while (pRun != NULL && strcmp(pRun->username, pNew->username) < 0) {
  795.                             pTrail = pRun;
  796.                             pRun = pRun->pNext;
  797.                             }
  798.                         pTrail->pNext = pNew;
  799.                         pNew->pNext=pRun;
  800.                     }
  801.                      break;
  802.             case 3:printf ("What account do you want to delete?");
  803.                    scanf ("%s", username);
  804.                    deleteNode(&pUsers, username);
  805.                    break;
  806.             case 4:displayAllRecur(pUsers);
  807.                    displayAll(pUsers);
  808.                    break;
  809.             case 5:freeAll(&pUsers);
  810.                    end=0;
  811.         }
  812.     }while(end);
  813.    
  814.    return 0;
  815. }
  816.    
  817.    
  818. /*  do{
  819.        
  820.         pNew=malloc(sizeof(userType));
  821.         signUp(pNew);
  822.         (*pNew).pNext = NULL; //pNew->pNext = NULL
  823.        
  824.         if (pUsers == NULL) //if initially empty
  825.             pUsers = pNew; //pNew is the first node
  826.         else //connect nodes to the list
  827.             pLast->pNext = pNew;
  828.        
  829.         pLast = pNew;
  830.    
  831.         printf("Another user?");
  832.         scanf("%d%c",&opt,&cDump);
  833.        
  834.     }while(opt == 1);
  835. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement