Advertisement
Guest User

MP

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