Advertisement
Guest User

halp

a guest
Mar 25th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.75 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. Rivera, Miguel Fernando Cua, 11610794
  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 {
  21. string20 first,middle,last;
  22. }nameType; //Structure for the user's name
  23.  
  24. typedef struct{
  25. nameType name;
  26. string50 address;
  27. }userInfoType; //Structure for user information
  28.  
  29. typedef struct{
  30. string8 code;
  31. int qty;
  32. }prodBoughtType; //Structure for the cart
  33.  
  34. typedef struct{
  35. string8 productcode;
  36. string15 supplier,
  37. product;
  38. int quantityavailable,
  39. quantitysold;
  40. float purchaseprice,
  41. unitsellingprice,
  42. discountrate;
  43.  
  44. }productListType; //Product List structure
  45. typedef struct productListType productType;
  46. typedef productType * ptrProduct;
  47.  
  48. typedef struct{
  49. string15 category;
  50. ptrProduct pFirst;
  51. } categoryType;
  52. typedef categoryType aCategories[10];
  53. //typedef struct stockTag stockType;
  54. //typedef stockType * ptrStock; //Stocks Structure
  55.  
  56. typedef prodBoughtType arrBought[MAX_CART];
  57. struct userTag{
  58.  
  59. string15 username,
  60. password;
  61. userInfoType info;
  62. char type;
  63. float creditlimit,
  64. outstanding;
  65. arrBought cart;
  66. int nItems,
  67. nLocked,
  68. nLoggedin;
  69. struct userTag *pNext;
  70. };
  71. typedef struct userTag userType;
  72. typedef userType * ptrUser; //User Information Structure
  73.  
  74. //Function Name: prodcode
  75. //Function Required Input Parameters: N/A
  76. //Function Expected Return Data: Product code with first letters of category, supplier and product as initial
  77. //Function Description and or Algorithim: obtain the first letters, concatenate, then place randomly generated numbers at end
  78. productType* prodcode (categoryType *pStock)
  79. {
  80. int i;
  81. char tempcode [3] = {0};
  82. char categoryinitial = (*pStock).category[0];
  83. char supplierinitial = (*pStock).pFirst.supplier[0];
  84. char productinitial = (*pStock).pFirst.product[0];
  85.  
  86. if ((*pStock).category==NULL)
  87. categoryinitial = 0;
  88. if ((*pStock).supplier == NULL)
  89. supplierinitial = 0;
  90. if ((*pStock).pStockInfo.product == NULL)
  91. productinitial = 0;
  92.  
  93. (*pStock).pStockInfo.productcode[0] = categoryinitial;
  94. (*pStock).pStockInfo.productcode[1] = supplierinitial;
  95. (*pStock).pStockInfo.productcode[2] = productinitial;
  96.  
  97. for (i=3;i<=8;i++)
  98. (*pStock).pStockInfo.productcode[i] = (rand() % 10) + '0';
  99.  
  100.  
  101. for (i=0;i<2;i++){
  102.  
  103. if ((*pStock).pStockInfo.productcode[i] > 'a' && (*pStock).pStockInfo.productcode[i] < 'z')
  104. (*pStock).pStockInfo.productcode[i] -= 32;
  105. }
  106.  
  107.  
  108.  
  109. }
  110.  
  111. //Function Name: search
  112. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  113. //Function Expected Return Data: Address of username that is the same as the one passed to it
  114. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
  115. userType* search (userType* pFirst, string15 username)
  116. {
  117. ptrUser pRun;
  118.  
  119. pRun = pFirst;
  120.  
  121. while (pRun != NULL && strcmp(username, pRun->username)!=0)
  122. pRun = pRun->pNext;
  123.  
  124. return pRun;
  125. }
  126.  
  127. //Function Name: searchStock
  128. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  129. //Function Expected Return Data: Address of product that is the same as the one passed to it
  130. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
  131. categoryType* searchStock (categoryType *pFirst, string15 product)
  132. {
  133.  
  134. ptrStock pRun;
  135.  
  136. pRun = pFirst;
  137.  
  138. while (pRun != NULL && strcmp(product, (*pRun).pStockInfo.product)!=0)
  139. pRun = pRun->pNext;
  140.  
  141. return pRun;
  142.  
  143. }
  144.  
  145. //Function Name: searchCategory
  146. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  147. //Function Expected Return Data: Address of category that is the same as the one passed to it
  148. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
  149. categoryType* searchCategory (categoryType *pFirst, string15 category)
  150. {
  151. ptrStock pRun;
  152.  
  153. pRun = pFirst;
  154.  
  155. while (pRun != NULL && strcmp(category, (*pRun).category)!=0)
  156. pRun = pRun->pNext;
  157.  
  158. return pRun;
  159.  
  160.  
  161. }
  162.  
  163. //Function Name: searchSupplier
  164. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  165. //Function Expected Return Data: Address of supploer that is the same as the one passed to it
  166. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
  167. categoryType* searchSupplier (categoryType *pFirst, string15 supplier)
  168. {
  169. ptrStock pRun;
  170.  
  171. pRun = pFirst;
  172.  
  173. while (pRun != NULL && strcmp(supplier, (*pRun).pStockInfo.supplier)!=0)
  174. pRun = pRun->pNext;
  175.  
  176. return pRun;
  177.  
  178.  
  179. }
  180.  
  181. //Function Name: searchProductCode
  182. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  183. //Function Expected Return Data: Address of product code that is the same as the one passed to it
  184. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
  185. /*productType* searchProductCode (categoryType *pFirst, string8 productcode)
  186. {
  187. ptrStock pRun;
  188.  
  189. pRun = pFirst;
  190.  
  191. while (pRun != NULL && strcmp(productcode, (*pRun).pStockInfo.productcode)!=0)
  192. pRun = pRun->pNext;
  193.  
  194. return pRun;
  195.  
  196. }
  197. */
  198. //Function Name: IsUnique
  199. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  200. //Function Expected Return Data: 1 if the username cannot be found in the structure (if it is unique) or 0 if the username is in the function (it is not unique).
  201. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return 1 or 0 depending on whether or not username was found.
  202. int IsUnique (userType *pUsers, string15 username)
  203. {
  204. ptrUser pRun;
  205.  
  206. pRun = pUsers;
  207.  
  208. while (pRun != NULL && strcmp(username, pRun->username)!=0)
  209. pRun = pRun->pNext;
  210.  
  211. if (pRun == NULL)
  212. return 1;
  213. else
  214. return 0;
  215.  
  216.  
  217. }
  218.  
  219. //Function Name: IsUniqueStock
  220. //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
  221. //Function Expected Return Data: 1 if the product cannot be found in the structure (if it is unique) or 0 if the product is in the function (it is not unique).
  222. //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return 1 or 0 depending on whether or not product was found.
  223. int IsUniqueStock (categoryType *pStock, string15 product)
  224. {
  225.  
  226. ptrStock pRun;
  227.  
  228. pRun = pStock;
  229.  
  230. while (pRun != NULL && strcmp (product, (*pRun).pStockInfo.product)!=0)
  231. pRun = pRun->pNext;
  232.  
  233. if (pRun == NULL)
  234. return 1;
  235. else if (pRun != NULL)
  236. return 0;
  237.  
  238.  
  239.  
  240. }
  241. /*
  242. void AdminSaveInventory (categoryType *pStock)
  243. {
  244. ptrStock pRun;
  245. string20 savelocation;
  246. char cDump;
  247.  
  248. pRun = pStock;
  249.  
  250. printf("Input file name where stock information will be saved. \n");
  251. printf("Input: ",savelocation, &cDump );
  252. pStock = fopen("%s.txt", "w", savelocation);
  253.  
  254. while (pRun != NULL){
  255.  
  256. fprintf("%s %s %s \n", pRun->category, pRun->productcode, pRun->product);
  257. fprintf("%d %f %s \n", pRun->quantityavailable, pRun->purchaseprice, pRun->supplier);
  258. fprintf("%f & % %d \n", pRun->sellingprice, pRun->discountrate, pRun->quantitysold);
  259. fprintf("\n");
  260.  
  261. pRun=pRun->pNext;
  262. }
  263.  
  264.  
  265. }
  266. */
  267.  
  268. //Function Name: AddStock
  269. //Function Required Input Parameters: A pointer where the new address will point to e.g. pNew and the structure pointer.
  270. //Function Expected Return Data: N/A
  271. //Function Description and or Algorithim: Adds a new stock by asking for a category, supplier, product.
  272. void AddStock (categoryType *pNewStock, categoryType *pStock)
  273. {
  274. int exit = 0, strikes = 0, tempinteger = 0;
  275. float tempfloat = 0;
  276. char cDump;
  277.  
  278.  
  279. do {
  280.  
  281. printf("Input the Category: ");
  282. fgets(pNewStock->category,16,stdin);
  283.  
  284. if (IsUniqueStock(pStock, pStock->category)==0)
  285. strikes++;
  286.  
  287. printf("Input the Supplier: ");
  288. scanf("%s%c", (*pNewStock).pStockInfo.supplier, &cDump);
  289.  
  290. if (IsUniqueStock(pStock, (*pStock).pStockInfo.supplier)==0)
  291. strikes++;
  292.  
  293. printf("Input the Product Name: ");
  294. scanf("%s%c", (*pNewStock).pStockInfo.product, &cDump);
  295.  
  296. if (IsUniqueStock(pStock, (*pStock).pStockInfo.product)==0)
  297. strikes++;
  298.  
  299. if (strikes == 3){
  300. printf("This product already exists, use the Modify, Restock or add new stock with a different name \n");
  301. exit = 0;
  302. }
  303.  
  304. printf("Input the Quantity Available for this product: ");
  305. scanf("%d%c", &tempinteger, &cDump);
  306. (*pNewStock).pStockInfo.quantityavailable = tempinteger;
  307. printf("Input the Purchase Price for this product: ");
  308. scanf("%f%c", &tempfloat, &cDump);
  309. (*pNewStock).pStockInfo.quantityavailable = tempfloat;
  310. printf("Input the Unit Selling Price for this product: ");
  311. scanf("%f%c", &tempfloat, &cDump);
  312. (*pNewStock).pStockInfo.quantityavailable = tempfloat;
  313. printf("Input the Discount Rate for this product: ");
  314. scanf("%f%c", &tempfloat, &cDump);
  315. (*pNewStock).pStockInfo.quantityavailable = tempfloat;
  316. (*pNewStock).pStockInfo.quantitysold = 0;
  317. prodcode (pNewStock);
  318. printf("Product Code of this Item: %s \n", (*pNewStock).pStockInfo.productcode);
  319.  
  320.  
  321.  
  322. printf("Press [1] to add new stock or [0] to return to manage stocks menu: ");
  323. scanf("%d%c", &exit, &cDump);
  324.  
  325. if(exit>1||exit<0)
  326. {
  327. printf("Invalid input. Returning to manage stocks menu");
  328. exit = 1;
  329. }
  330.  
  331.  
  332. }while(exit == 1);
  333.  
  334. }
  335.  
  336. //Function Name: AdminModifyStockMenu
  337. //Function Required Input Parameters: Product code of item to be modified
  338. //Function Expected Return Data: N/A
  339. //Function Description and or Algorithim: Modifies stock by asking for the product code then giving the administrator the option to modify the category, supplier, or the product name.
  340. void AdminModifyStockMenu (categoryType *pStock)
  341. {
  342. int choice, exit;
  343. char cDump;
  344. string8 comparecode, comparecategory, comparesupplier;
  345.  
  346. ptrStock pRun;
  347.  
  348. do {
  349.  
  350. printf("Input product code of product to be modified \n");
  351. printf("Input: "); scanf("%s%c", comparecode, &cDump);
  352.  
  353.  
  354. while (pRun != NULL && strcmp(comparecode, (*pRun).pStockInfo.productcode)!=0)
  355. pRun = pRun->pNext;
  356.  
  357. if (pRun == NULL)
  358. printf("Product Code not found, please try again. \n");
  359.  
  360.  
  361.  
  362. printf("MODIFY STOCK INFO \n");
  363. printf("Product code: %s \n", (*pStock).pStockInfo.productcode);
  364. printf("[1] Modify Category \n");
  365. printf("[2] Modify Supplier \n");
  366. printf("[3] Modify Product \n");
  367. printf("[4] Modify Purchase Price \n");
  368. printf("[5] Modify Selling Price \n");
  369. printf("[6] Modify Discount \n");
  370. printf("[7] Finish Modifications of Product %s \n", (*pStock).pStockInfo.productcode);
  371. printf("[0] Return to Administrator Menu");
  372. printf("Input: ");
  373. scanf("%d%c", &choice, &cDump);
  374.  
  375. switch (choice){
  376. case 1: do{
  377.  
  378. printf("Input new category for this product: ");
  379. scanf("%s%c", comparecategory, &cDump);
  380.  
  381. if (searchCategory (pStock, comparecategory)==NULL){
  382. printf("Category not found. Creating a new one. \n");
  383. strcpy(pStock->category, comparecategory);
  384. printf("New category for this product is %s.\n", pStock->category);
  385. }
  386. printf("Modified category for this product is %s. \n", pStock->category);
  387. printf("[1] Modify Category \n");
  388. printf("[0] Return to Modify Stocks Info Menu \n");
  389. printf("Input: ");
  390. scanf("%d%c", &exit, &cDump);
  391.  
  392. if(exit>1||exit<0)
  393. {
  394. printf("Invalid input! returning you to main menu");
  395. exit = 0;
  396.  
  397. }
  398.  
  399. }while(exit==1);
  400.  
  401. break;
  402. case 2: do {
  403.  
  404. printf("Input new supplier for this product: ");
  405. scanf("%s%c", comparesupplier, &cDump);
  406.  
  407. if (searchSupplier (pStock, comparesupplier)==NULL){
  408. printf("Supplier not found. Creating a new one. \n");
  409. strcpy((*pStock).pStockInfo.supplier, comparesupplier);
  410. printf("New supplier for this product is %s.\n", pStock->category);
  411. }
  412. printf("Modified supplier for this product is %s. \n", pStock->category);
  413. printf("[1] Modify Supplier \n");
  414. printf("[0] Return to Modify Stocks Info Menu: \n");
  415. printf("Input: ");
  416. scanf("%d%c", &exit, &cDump);
  417.  
  418.  
  419. if(exit>1||exit<0)
  420. {
  421. printf("Invalid input! returning you to main menu");
  422. exit = 0;
  423.  
  424. }
  425.  
  426. }while (exit== 1);
  427.  
  428. break;
  429. case 3: do {
  430.  
  431. printf("Input new product name for this item: ");
  432. scanf("%s%c", comparesupplier, &cDump);
  433.  
  434.  
  435. printf("Modified product name for this product is %s. \n", pStock->category);
  436. printf("[1] Modify Product Name \n");
  437. printf("[0] Return to Modify Stocks Info Menu \n");
  438. printf("Input: ");
  439. scanf("%d%c", &exit, &cDump);
  440.  
  441.  
  442.  
  443. if(exit>1||exit<0)
  444. {
  445. printf("Invalid input! returning you to main menu");
  446. exit = 0;
  447.  
  448. }
  449.  
  450. }while (exit==1);
  451.  
  452. break;
  453. case 4: do {
  454.  
  455. printf("Input new purchase price for product: ");
  456. scanf("%f%c", (*pStock).pStockInfo.purchaseprice, &cDump);
  457. printf("New purchase price: %.2f \n", (*pStock).pStockInfo.purchaseprice);
  458. printf("[1] Modify Purchase Price \n");
  459. printf("[0] Return to Modify Stocks Info Menu \n");
  460. printf("Input: ");
  461. scanf("%d%c", &exit, &cDump);
  462.  
  463. if(exit>1||exit<0)
  464. {
  465. printf("Invalid input! returning you to main menu");
  466. exit = 0;
  467.  
  468. }
  469.  
  470. }while (exit == 1);
  471.  
  472. break;
  473. case 5: do {
  474.  
  475. printf("Input new selling price: ");
  476. scanf("%f%c", (*pStock).pStockInfo.unitsellingprice, &cDump);
  477. printf("New selling price: %.2f \n", (*pStock).pStockInfo.unitsellingprice);
  478. printf("[1] Modify Selling Price \n");
  479. printf("[0] Return to Modify Stocks Info Menu \n");
  480. printf("Input: ");
  481. scanf("%d%c", &exit, &cDump);
  482.  
  483. if(exit>1||exit<0)
  484. {
  485. printf("Invalid input! returning you to main menu");
  486. exit = 0;
  487.  
  488. }
  489.  
  490. }while (exit==1);
  491.  
  492. break;
  493. case 6: do {
  494.  
  495. printf("Input new discount: ");
  496. scanf("%f%c", (*pStock).pStockInfo.discountrate, &cDump);
  497. printf("New discount for this product: %f % ", (*pStock).pStockInfo.discountrate);
  498. printf("[1] Modify Selling Price \n");
  499. printf("[0] Return to Modify Stocks Info Menu \n");
  500. printf("Input: ");
  501. scanf("%d%c", &exit, &cDump);
  502.  
  503. if(exit>1||exit<0)
  504. {
  505. printf("Invalid input! returning you to main menu");
  506. exit = 0;
  507.  
  508. }
  509.  
  510. }while (exit==1);
  511.  
  512. break;
  513. case 7: do {
  514. printf("Finishing Modification of Product.. \n");
  515. prodcode (pStock);
  516. printf("Press [0] return to main menu");
  517. scanf("%d", &exit);
  518.  
  519. if(exit>1||exit<0)
  520. {
  521. printf("Invalid input! returning you to main menu");
  522. exit = 0;
  523.  
  524. }
  525.  
  526. }while (exit==1);
  527.  
  528. break;
  529. default:
  530. break;
  531. }
  532.  
  533. }while(choice > 0 && choice < 8 );
  534.  
  535.  
  536.  
  537. }
  538.  
  539. //Function Name: AdminPrepareDelivery
  540. //Function Required Input Parameters: The user, user info and stock structure as well as a new pointer
  541. //Function Expected Return Data: N/A
  542. //Function Description and or Algorithim: Prints out the items in the cart and their total price
  543. void AdminPrepareDelivery (userType *pUsers, categoryType *pStock, categoryType *pNewStock, userInfoType *pInfo)
  544. {
  545. char exit, cDump;
  546. ptrStock pTrail, pRun;
  547. ptrUser pRuns;
  548. float itemsubtotal, totalprice;
  549.  
  550. do {
  551.  
  552. pRuns = pUsers;
  553.  
  554. if (pRun != NULL){
  555.  
  556. printf("User ID: %s \n", pUsers->username);
  557. printf("Customer Name: %s, %s, %s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  558. printf("Delivery Address: %s \n", (*pInfo).address);
  559. printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
  560. //totalprice = (pUsers->cart)*(pStock->unitsellingprice);
  561. //itemsubtotal = (pStock->unitsellingprice) - (pStock->discountrate/100) * (pUsers->cart);
  562. printf("%s %s %d %f %f %f %f \n", (*pStock).pStockInfo.productcode, (*pStock).pStockInfo.product, pUsers->cart, (*pStock).pStockInfo.unitsellingprice,totalprice, (*pStock).pStockInfo.discountrate, itemsubtotal);
  563. }
  564.  
  565. printf("Number of Items: %d \n");
  566. printf("Total Discount: Php %d \n");
  567. printf("Bill Amount: Php %f \n");
  568. printf("Total Outstanding: Php %f \n");
  569.  
  570. pTrail = pRun;
  571. pRun = pRun->pNext;
  572.  
  573. printf("[B] Previous User \n");
  574. printf("[N] Next User \n");
  575. printf("[X] Return to Manage Stocks Menu \n");
  576. printf("Input: "); scanf("%c%c", &exit, &cDump);
  577.  
  578. if (exit == 'b' || exit == 'B')
  579. if (pTrail == NULL)
  580. printf("No previous user. \n");
  581. else
  582. printf("Exit function");
  583.  
  584.  
  585.  
  586. }while (exit == 'B' || exit == 'b'|| exit == 'n' || exit == 'N' && (exit != 'x' || exit != 'X'));
  587.  
  588.  
  589.  
  590.  
  591. }
  592. //Function Name: AdminManageStocks
  593. //Function Required Input Parameters: N/A.
  594. //Function Expected Return Data: N/A
  595. //Function Description and or Algorithim: Menu where the administrator can access the stocks. Stocks can added, viewed, reordered, restocked through this menu.
  596. void AdminManageStocks (userType *pUsers, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
  597. {
  598. int choice, exit, page = 0;
  599. char cDump, cExit = '\0';
  600. ptrStock pRun;
  601. string8 TempProdCode;
  602. string15 saveloc, TempCategory;
  603.  
  604. pStock = NULL;
  605. pNewStock = NULL;
  606. pEnd = NULL;
  607.  
  608.  
  609.  
  610. do {
  611.  
  612. printf("MANAGE STOCKS MENU \n");
  613. printf("[1] Add New Stock \n");
  614. printf("[2] View All Stocks \n");
  615. printf("[3] View Stocks by Category \n");
  616. printf("[4] View Stocks to Reorder \n");
  617. printf("[5] Modify Stock Info \n");
  618. printf("[6] Restock \n");
  619. printf("[7] Update Inventory from File \n");
  620. printf("[0] Return to Administrator Menu \n");
  621. printf("Input: ");
  622. scanf("%d%c", &choice, &cDump);
  623.  
  624. switch (choice){
  625. case 1: do{
  626. pNewStock = malloc(sizeof(categoryType));
  627.  
  628. AddStock(pNewStock, pStock);
  629.  
  630. pNewStock->pNext = NULL;
  631.  
  632. if (pStock == NULL) //if initially empty
  633. pStock = pNewStock; //pNew is the first node
  634.  
  635. else //connect nodes to the list
  636. pEnd->pNext = pNewStock;
  637.  
  638. pEnd = pNewStock;
  639.  
  640.  
  641. }while(exit==0);
  642.  
  643. break;
  644. case 2: do {
  645.  
  646. printf("Viewing All Stocks \n");
  647. pRun = pStock;
  648. printf("Category Supplier Product Qty Available Purchase Price Selling Price Qty Sold Product Code \n");
  649. while (pRun != NULL && page < 20){
  650.  
  651. printf("%s %s %s %d %f %f %d %s \n",
  652. pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
  653. pRun = pRun->pNext;
  654. page++;
  655. }
  656. page = 0;
  657. printf("Press [N] return to main menu or ENTER to view next page. \n");
  658. scanf("%c%c", &cExit, &cDump);
  659. }while (cExit=='\0');
  660.  
  661. break;
  662. case 3: do {
  663.  
  664. printf("Input the category");
  665. printf("Input: ");scanf("%s%c",TempCategory, &cDump);
  666.  
  667. searchStock (pStock, TempCategory);
  668.  
  669. if (searchStock (pStock, TempCategory)==NULL)
  670. printf("Category not found \n");
  671. else if (searchStock (pStock, TempCategory)!=NULL)
  672. printf("Viewing Stocks by Category \n");
  673. pRun = pStock;
  674. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  675. while (pRun != NULL){
  676. if (strcmp(pStock->category,TempCategory)==0){
  677. printf("%s %s %s %d %f %f %d %s",
  678. pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
  679. pRun = pRun->pNext;
  680. }
  681. }
  682. printf("Press [0] return to main menu");
  683. scanf("%d%c", &exit, &cDump);
  684. }while (exit==1);
  685.  
  686. break;
  687. case 4: do {
  688. printf("Viewing Stocks to Reorder \n");
  689. pRun = pStock;
  690. do{
  691.  
  692. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  693. printf("%s %s %s %d %f %f %d %s",
  694. pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
  695. pRun = pRun->pNext;
  696. page++;
  697.  
  698. }while (pRun != NULL && (*pRun).pStockInfo.quantityavailable == 0 && page < 20);
  699. page = 0;
  700. printf("Press [N] return to main menu or ENTER to view next page. \n");
  701. scanf("%c%c", &cExit, &cDump);
  702. }while (cExit=='\0');
  703.  
  704. break;
  705. case 5: do {
  706. printf("Viewing All Stocks \n");
  707. pRun = pStock;
  708. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  709. while (pRun != NULL){
  710.  
  711. printf("%s %s %s %d %f %f %d %s",
  712. pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
  713. pRun = pRun->pNext;
  714. }
  715.  
  716. printf("Modify Stock Info \n");
  717. AdminModifyStockMenu(pStock);
  718. printf("Press [0] return to main menu");
  719. scanf("%d%c", &exit, &cDump);
  720. }while (exit==1);
  721.  
  722. break;
  723. case 6: do {
  724. printf("Restock \n");
  725. pRun = pStock;
  726. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  727. while (pRun != NULL){
  728.  
  729. printf("%s %s %s %d %f %f %d %s",
  730. pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
  731. pRun = pRun->pNext;
  732. }
  733. printf("Input the product code of the product that will be restocked: ");
  734. scanf("%s%c",TempProdCode, &cDump);
  735. pRun = pStock;
  736. while (pRun != NULL && strcmp(TempProdCode, (*pRun).pStockInfo.productcode)!=0){
  737. pRun = pRun->pNext;
  738.  
  739. if (pRun == NULL){
  740. printf("Last input product code not found. Not restocked. Returning to Manage Stocks Menu \n");
  741. exit = 0;
  742. }
  743.  
  744. if (pRun != NULL && strcmp(TempProdCode, (*pRun).pStockInfo.productcode)==0){
  745. printf("Additional Quantity for this item: ");
  746. scanf("%d%c", (*pRun).pStockInfo.quantityavailable, &cDump);
  747. printf("This product has been restocked and has %d quantity available. \n", (*pRun).pStockInfo.quantityavailable);
  748. }
  749. }
  750. printf("Press [0] return to main menu");
  751. scanf("%d%c", &exit, &cDump);
  752. }while (exit==1);
  753.  
  754. break;
  755. case 7: do {
  756. printf("Input save location: ");
  757. scanf("%s%c", saveloc, &cDump);
  758. printf("Press [0] return to main menu");
  759. scanf("%d", &exit);
  760. }while (exit==1);
  761.  
  762. break;
  763. default: choice = 0;
  764. break;
  765. }
  766.  
  767. }while(choice > 0 && choice < 9 );
  768.  
  769.  
  770. }
  771.  
  772. //Function Name: AdminManageAccounts
  773. //Function Required Input Parameters: N/A
  774. //Function Expected Return Data: N/A
  775. //Function Description and or Algorithim: Menu where administrator can access the shopper accounts registered in the kiosk. Here the administrator can unlock certain users or unlock all, as well as view those with outstanding.
  776. void AdminManageAccounts (userType *pUsers, userInfoType *pInfo)
  777. {
  778. int choice = 0, exit;
  779. char cDump, yesorno;
  780. string15 CompareUser;
  781. userType *pLock;
  782. ptrUser pRun;
  783.  
  784. pRun = pUsers;
  785.  
  786. do {
  787.  
  788. printf("Welcome, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  789. printf("MANAGE ACCOUNTS MENU \n");
  790. printf("[1] View Locked Accounts \n");
  791. printf("[2] Unlock Specific Account \n");
  792. printf("[3] Unlock All Locked Accounts \n");
  793. printf("[4] View Accounts with Outstanding Balance \n");
  794. printf("[0] Return to Administrator Menu \n");
  795. printf("Input: ");
  796. scanf("%d%c", &choice, &cDump);
  797.  
  798. switch (choice) {
  799.  
  800. case 1: do {
  801.  
  802. while (pRun != NULL && pUsers->nLocked == 1){
  803. pRun = pRun->pNext;
  804. printf("Username: %s \n", pRun->username);
  805. printf("Name: %s, %s ,%s",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  806. if (pRun->username == NULL)
  807. printf("No account is locked. \n");
  808. }
  809.  
  810. printf("[0] Return to Manage Accounts Menu \n");
  811. printf("[1] View All Locked Accounts \n");
  812. printf("Input: ");scanf("%d", &exit);
  813.  
  814. if(exit>1||exit<0)
  815. {
  816. printf("Invalid input. Returning to Manage Accounts Menu \n");
  817. exit = 1;
  818. }
  819.  
  820. } while(exit == 1);
  821.  
  822. pRun = NULL;
  823. free(pRun);
  824.  
  825. break;
  826.  
  827. case 2: do {
  828.  
  829. printf("Input username of locked account. \n");
  830. printf("Input: ");scanf("%s%c", CompareUser, &cDump);
  831.  
  832. pLock = search (pUsers, CompareUser);
  833.  
  834. if (pLock != NULL)
  835. pLock->nLocked = 0;
  836.  
  837.  
  838. printf("[0] Return to Manage Accounts Menu \n");
  839. printf("[1] Unlock Another Account\n");
  840. printf("Input: ");scanf("%d", &exit);
  841.  
  842. if(exit>1||exit<0)
  843. {
  844. printf("Invalid input. Returning to Manage Accounts Menu \n");
  845. exit = 1;
  846. }
  847.  
  848. } while(exit == 1);
  849.  
  850. break;
  851.  
  852. case 3: do {
  853.  
  854. printf("Would you like to unlock all locked accounts? [Y]es | [N]o \n");
  855. scanf("%c%c",&yesorno, &cDump);
  856.  
  857. if (yesorno == 'y' || yesorno == 'Y'){
  858. while (pRun != NULL ){
  859. if (pRun->nLocked == 1)
  860. pRun->nLocked = 0;
  861.  
  862. pRun = pRun->pNext;
  863. }
  864. }
  865.  
  866. printf("[0] Return to Manage Accounts Menu \n");
  867. printf("Input: ");scanf("%d%c", &exit, &cDump);
  868.  
  869. if(exit>1||exit<0)
  870. {
  871. printf("Invalid input. Returning to Manage Accounts Menu \n");
  872. exit = 1;
  873. }
  874.  
  875. } while(exit == 1);
  876.  
  877. break;
  878. case 4: do {
  879.  
  880. printf("Diplaying Accounts with Outstanding Balance \n");
  881. while (pRun != NULL){
  882. if (pRun->outstanding>0){
  883.  
  884. printf("%s \n", pRun->username);
  885. printf("%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  886. printf("%f \n", pRun->outstanding);
  887. }
  888. }
  889.  
  890. printf("[0] Return to Manage Accounts Menu \n");
  891. printf("Input: ");scanf("%d", &exit);
  892.  
  893. if(exit>1||exit<0)
  894. {
  895. printf("Invalid input. Returning to Manage Accounts Menu \n");
  896. exit = 1;
  897. }
  898.  
  899. }while (exit == 1);
  900. break;
  901. default: printf("Returning to Administrator Menu.. \n");
  902. break;
  903. }
  904.  
  905. } while (choice > 0 && choice < 5);
  906.  
  907. }
  908.  
  909.  
  910.  
  911. //Function Name: SignUp
  912. //Function Required Input Parameters: Username and Password of account to be made. Authorization code if administrator account is to be made by user.
  913. //Function Expected Return Data: N/A
  914. //Function Description and or Algorithim: Menu where administrator can access the shopper accounts registered in the kiosk. Here the administrator can unlock certain users or unlock all, as well as view those with outstanding.
  915. void signUp (userType *pUser, userType *pUsers)
  916. {
  917. int unique = 0;
  918. char cDump, choice, cTempType = '\0';
  919. char arrInputCode[9];
  920. char arrCompareCode[9] = {"DLSU2017"};
  921. string15 TempUsername;
  922.  
  923.  
  924. do{
  925. printf("Enter username: ");
  926. scanf("%s%c", (*pUser).username /*TempUsername*/,&cDump); //placing the information directly within the container. Username is inside pUser
  927.  
  928. if (IsUnique (pUsers, pUser->username) == 0){
  929. printf("Username taken, please input a unique username. \n");
  930. unique = 0;
  931. }
  932.  
  933. else if (IsUnique (pUsers, pUser->username) == 1){
  934.  
  935. unique = 1;
  936. printf("Username is unique, proceeding. \n");
  937. }
  938.  
  939. }while (strlen((*pUser).username)<3 || strlen((*pUser).username)>15 || unique != 1);
  940.  
  941. do{
  942. printf("Enter password: ");
  943. scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
  944. if (strlen((*pUser).password)<6){
  945.  
  946. printf("Password too short, please try again. \n");
  947. printf("Enter password: ");
  948. scanf("%s%c", (*pUser).password,&cDump);
  949. }
  950. if (strlen((*pUser).password)>15){
  951.  
  952. printf("Password too long, please try again. \n");
  953. printf("Enter password: ");
  954. scanf("%s%c", (*pUser).password,&cDump);
  955. }
  956.  
  957. if (ValidPass(pUser)==1)
  958. printf("Password is valid. \n");
  959. else{
  960. printf("Error, password must contain non-letter character.\n");
  961. printf("Enter password: ");
  962. scanf("%s%c", (*pUser).password,&cDump);
  963. }
  964.  
  965.  
  966. }while (strlen((*pUser).password)<6 || strlen((*pUser).password)>15);
  967.  
  968.  
  969.  
  970.  
  971.  
  972. printf("Create [S]hopper or [A]dministrator account? \n");
  973. printf("Input: ");
  974. scanf("%c%c", &cTempType, &cDump);
  975.  
  976. if(cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
  977. printf("Invalid input, please try again: \n");
  978. while (cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
  979. printf("Input: ");
  980. scanf("%c%c",&cTempType, &cDump);
  981. }
  982. }
  983.  
  984.  
  985. if (cTempType == 's' || cTempType == 'S'){
  986.  
  987. (*pUser).type = 'S';
  988. printf("Account Type: Shopper \n");
  989. (*pUser).creditlimit = 5000.00;
  990. printf("Your current Credit Limit is Php 5000.00. \n");
  991. (*pUser).outstanding = 0.00;
  992. printf("Your current Outstanding Balance is Php 0.00. \n");
  993.  
  994. }
  995.  
  996. else if (cTempType == 'a' || cTempType == 'A'){
  997.  
  998.  
  999. do {
  1000. printf("Input authorization code: ");
  1001. scanf("%s%c", arrInputCode,&cDump);
  1002.  
  1003. if (strcmp(arrInputCode,arrCompareCode)==0){
  1004.  
  1005. (*pUser).type = 'A';
  1006. //AdminChoice();
  1007. printf("Account Type: Admin \n");
  1008.  
  1009. }
  1010.  
  1011. else
  1012. printf("Invalid authorization code, try again. Please try again. \n");
  1013.  
  1014.  
  1015.  
  1016. }while (strcmp(arrInputCode,arrCompareCode)!=0);
  1017.  
  1018.  
  1019. }
  1020. }
  1021.  
  1022. /*void capitalize (userType *pUsers, userInfoType *pInfo)
  1023. {
  1024. char arrTemp[16];
  1025.  
  1026.  
  1027.  
  1028. if ((*pInfo).name.first[1] > 'a' || (*pInfo).name.first[1] < 'z' )
  1029. (*pInfo).name.first[1] -= 32;
  1030.  
  1031. }
  1032. */
  1033.  
  1034. //Function Name: modifyUserInfo
  1035. //Function Required Input Parameters: N/A
  1036. //Function Expected Return Data: N/A
  1037. //Function Description and or Algorithim: Menu where shopper can access the information of his account and change them if needed.
  1038. void modifyUserInfo (userType *pUser, userInfoType *pInfo)
  1039. {
  1040. int choice = 0, exit = 0;
  1041. char cDump;
  1042. char arrComparePass[16];
  1043.  
  1044.  
  1045.  
  1046. do {
  1047.  
  1048. printf("Hello, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1049. printf("What would you like to change? \n");
  1050. printf("[1] Change Name \n");
  1051. printf("[2] Change Address \n");
  1052. printf("[3] Change Password \n");
  1053. printf("[0] Return to Shopper Menu \n");
  1054. printf("Input: ");
  1055. scanf("%d%c", &choice, &cDump);
  1056.  
  1057. switch (choice) {
  1058.  
  1059. case 1: do {
  1060.  
  1061. printf("Change First Name: ");
  1062. fgets((*pInfo).name.first,21,stdin);
  1063. if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
  1064. (*pInfo).name.first[0] -= 32;
  1065.  
  1066. printf("Change Middle Name: ");
  1067. fgets((*pInfo).name.middle,21,stdin);
  1068. if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
  1069. (*pInfo).name.middle[0] -= 32;
  1070.  
  1071. printf("Change Last Name: ");
  1072. fgets((*pInfo).name.last,51,stdin);
  1073. if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
  1074. (*pInfo).name.last[0] -= 32;
  1075.  
  1076.  
  1077.  
  1078. printf("Your new name is: %s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1079. printf("[0] Return to Modify User Info Menu \n");
  1080. printf("[1] Reinput Name \n");
  1081. printf("Input: ");scanf("%d%c", &exit, &cDump);
  1082.  
  1083. if(exit>1||exit<0)
  1084. {
  1085. printf("Invalid input! returning you to main menu");
  1086. exit = 1;
  1087. }
  1088.  
  1089. } while(exit == 1);
  1090.  
  1091. break;
  1092.  
  1093. case 2: do {
  1094.  
  1095. printf("Input your new Address: ");
  1096. fgets((*pInfo).address,51,stdin);
  1097. (*pInfo).address[strlen((*pInfo).address)-1]='\0';
  1098. printf("Your new Address is: %s \n",(*pInfo).address);
  1099. printf("[0] Return to Modify User Info Menu \n");
  1100. printf("[1] Reinput Address\n");
  1101. printf("Input: ");scanf("%d%c", &exit, &cDump);
  1102. if(exit>1||exit<0)
  1103. {
  1104. printf("Invalid input! returning you to main menu");
  1105. exit = 1;
  1106. }
  1107.  
  1108. } while(exit == 1);
  1109.  
  1110. break;
  1111.  
  1112. case 3: do {
  1113.  
  1114. while (strcmp((*pUser).password, arrComparePass)!=0){
  1115. printf("Input your current password. \n");
  1116. scanf("%s%c",arrComparePass,&cDump);
  1117. if(strcmp((*pUser).password, arrComparePass)!=0){
  1118. printf("Password does not match, please try again. \n");
  1119. printf("Input: "); scanf("%s%c", arrComparePass,&cDump);
  1120. }
  1121. }
  1122.  
  1123. printf("Input your new Password: ");
  1124. scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
  1125. if (strlen((*pUser).password)<6){
  1126.  
  1127. printf("Password too short, please try again. \n");
  1128. printf("Enter password: ");
  1129. scanf("%s%c", (*pUser).password,&cDump);
  1130. }
  1131. if (strlen((*pUser).password)>15){
  1132.  
  1133. printf("Password too short, please try again. \n");
  1134. printf("Enter password: ");
  1135. scanf("%s%c", (*pUser).password,&cDump);
  1136. }
  1137.  
  1138. if (ValidPass(pUser)==1)
  1139. printf("Password is valid. \n");
  1140. else{
  1141. printf("Error, password must contain non-letter character.\n");
  1142. printf("Enter password: ");
  1143. scanf("%s%c", (*pUser).password,&cDump);
  1144. }
  1145.  
  1146. printf("Your new Password is %s. \n", (*pUser).password);
  1147.  
  1148. printf("[0] Return to Modify User Info Menu \n");
  1149. printf("[1] Reinput Address\n");
  1150. printf("Input: ");scanf("%d", &exit);
  1151.  
  1152. if(exit>1||exit<0)
  1153. {
  1154. printf("Invalid input! returning you to main menu");
  1155. exit = 1;
  1156. }
  1157.  
  1158. } while(exit == 1);
  1159.  
  1160. break;
  1161.  
  1162. default: choice = 0;
  1163.  
  1164. }
  1165.  
  1166. } while (choice == 1 || choice == 2 || choice == 3);
  1167.  
  1168. }
  1169.  
  1170. //Function Name: getUserInfo
  1171. //Function Required Input Parameters: User's whole name and address
  1172. //Function Expected Return Data: N/A
  1173. //Function Description and or Algorithim: To be done after signUp function, user is prompted to enter their name and address.
  1174. void getUserInfo (userInfoType *pInfo)
  1175. {
  1176.  
  1177. printf("Enter name: \n");
  1178. printf("First Name: ");
  1179. fgets((*pInfo).name.first,21,stdin);
  1180. if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
  1181. (*pInfo).name.first[0] -= 32;
  1182. printf("Middle Name: ");
  1183. fgets((*pInfo).name.middle,21,stdin);
  1184. if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
  1185. (*pInfo).name.middle[0] -= 32;
  1186. printf("Last Name: ");
  1187. fgets((*pInfo).name.last,51,stdin);
  1188. if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
  1189. (*pInfo).name.last[0] -= 32;
  1190.  
  1191. printf("%s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1192.  
  1193.  
  1194.  
  1195.  
  1196. printf("Enter address: ");
  1197. fgets((*pInfo).address,51,stdin);
  1198.  
  1199. (*pInfo).address[strlen((*pInfo).address)-1]='\0';
  1200. (*pInfo).name.first[strlen((*pInfo).name.first)-1]='\0';
  1201. (*pInfo).name.middle[strlen((*pInfo).name.middle)-1]='\0';
  1202. (*pInfo).name.last[strlen((*pInfo).name.last)-1]='\0';
  1203.  
  1204. }
  1205.  
  1206. //Function Name: getUserInfo
  1207. //Function Required Input Parameters: N/A (Is passed the password)
  1208. //Function Expected Return Data: 1 or 0 depending on whether or not the password is valid.
  1209. //Function Description and or Algorithim: Checks whether or not there is a non-character present in the password.
  1210. int ValidPass (userType *pUser)
  1211. {
  1212. int i, valid=0;
  1213.  
  1214. for(i=0;i<(strlen(pUser->password));i++){
  1215. if (pUser->password[i] < 'a' || pUser->password[i] >'z')
  1216. if (pUser->password[i] < 'A' || pUser->password[i] >'Z')
  1217. valid=1;
  1218. }
  1219. return valid;
  1220.  
  1221. }
  1222.  
  1223. //Function Name: displayAll
  1224. //Function Required Input Parameters: N/A
  1225. //Function Expected Return Data: N/A
  1226. //Function Description and or Algorithim: Displays all users registered in the kiosk.
  1227. void displayAll (userType *pUsers)
  1228. {
  1229. while (pUsers!=NULL){ //stop traversing when there is no more new address
  1230.  
  1231. printf("%s\n", pUsers->username);
  1232. pUsers = pUsers->pNext; //node traversal
  1233.  
  1234. }
  1235.  
  1236.  
  1237. }
  1238.  
  1239. //Function Name: signIn
  1240. //Function Required Input Parameters: Unique username and password
  1241. //Function Expected Return Data: 1 or 2 depending on account type.
  1242. //Function Description and or Algorithim: Logs-in the user. If is an administrator, asks for authorization code.
  1243. int signIn (userType *pUsers, userInfoType *pInfo, userType *pNew, userType *pLast)
  1244. {
  1245. int loggedin=0, tries=3, exit = 0, AccountType = 0;
  1246. char arrTempUser[16], arrTempPW[16], arrInputCode[9], authcode[9]={"DLSU2017"};
  1247. char cDump;
  1248. userType *pLogin, *pPassword;
  1249.  
  1250. do{
  1251.  
  1252.  
  1253. printf("Enter username: ");
  1254. scanf("%s", arrTempUser);fflush(stdin);
  1255.  
  1256. printf("Enter password: ");
  1257. scanf("%s", arrTempPW);fflush(stdin);
  1258.  
  1259. if(pUsers!=NULL)
  1260. {
  1261. pLogin = search(pUsers, arrTempUser);
  1262. pPassword = search(pUsers, pUsers->username);
  1263.  
  1264. if (pLogin == NULL){
  1265.  
  1266. printf("Not found address\n");
  1267. signIn (pUsers, pInfo, pNew, pLast);
  1268. }
  1269. }
  1270. else if (pUsers == NULL)
  1271. {
  1272.  
  1273. printf("Not found was null\n");
  1274. signIn (pUsers, pInfo, pNew, pLast);
  1275. }
  1276.  
  1277. if (pUsers->nLocked == 1)
  1278. printf("This account is locked, contact an administrator, returning to main menu. \n");
  1279.  
  1280.  
  1281. if (strcmp(pLogin->username, arrTempUser)==0){
  1282.  
  1283. if (strcmp(pPassword->password, arrTempPW)==0){
  1284.  
  1285. pUsers->nLoggedin = 1;
  1286.  
  1287. }
  1288. else{
  1289. while (strcmp(pPassword->password, arrTempPW)!=0 && pUsers->nLocked != 1){
  1290.  
  1291. printf("Incorrect password, please try again. %d tries remaining: \n", tries);
  1292. tries--;
  1293. scanf("%s%c", arrTempPW, &cDump);
  1294.  
  1295. if (tries == 0){
  1296.  
  1297. printf("This account has been locked. Contact Administrator. Returning to main menu. \n");
  1298. pUsers->nLocked = 1;
  1299. exit = 1;
  1300.  
  1301. }
  1302. }
  1303.  
  1304. }
  1305. }
  1306. else {
  1307.  
  1308. printf("Incorrect username or password, please try again. %d tries remaining: \n", tries);
  1309. printf("%s", arrTempUser);
  1310. printf("%d", strcmp(pLogin->username, arrTempUser));
  1311. tries--;
  1312. }
  1313.  
  1314. if (pUsers->type == 'A' && pUsers->nLocked == 0){
  1315.  
  1316. printf("Input authorization code: ");
  1317. scanf("%s%c", arrInputCode, &cDump);
  1318.  
  1319. if (strcmp(arrInputCode,authcode)==0){
  1320.  
  1321. AccountType = 2;
  1322. pUsers->nLoggedin = 1;
  1323. loggedin = 1;
  1324. exit = 1;
  1325. return AccountType;
  1326. }
  1327.  
  1328. else{
  1329.  
  1330. while (strcmp(arrInputCode,authcode)!=0){
  1331.  
  1332. printf("Incorrect code, please try again.\n");
  1333. printf("Input: "); scanf("%s%c", arrInputCode, &cDump);
  1334.  
  1335.  
  1336. }
  1337.  
  1338.  
  1339.  
  1340. }
  1341. }
  1342.  
  1343. else if (pUsers->type == 'S' && pUsers->nLocked == 0){
  1344.  
  1345. printf("Welcome, %s \n", (*pInfo).name.first);
  1346. //pUsers->loggedin = 1;
  1347. //modifyUserInfo (pUsers, pInfo);
  1348. AccountType = 1;
  1349. return AccountType;
  1350. pUsers->nLoggedin = 1;
  1351. }
  1352.  
  1353. }while (loggedin == 0 && tries > 0 && exit == 0 && pUsers->nLocked != 1);
  1354.  
  1355. }
  1356.  
  1357.  
  1358. void freeAll (ptrUser *pFirst)
  1359. {
  1360. userType *pDel;
  1361.  
  1362. while(*pFirst != NULL){
  1363. pDel = *pFirst;
  1364. *pFirst = (*pFirst)->pNext;
  1365. free(pDel);
  1366. }
  1367.  
  1368. }
  1369. //Function Name: ShopperMenu
  1370. //Function Required Input Parameters: N/A
  1371. //Function Expected Return Data: N/A
  1372. //Function Description and or Algorithim: Displays the menu for the shopper accessing the kiosk.
  1373. void ShopperMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock)
  1374. {
  1375. int choice = 0, page = 20;
  1376. char cDump, cExit = '\0';
  1377. int exit;
  1378. string15 TempCategory;
  1379. ptrStock pRun;
  1380.  
  1381. do {
  1382. printf("SHOPPER MENU \n");
  1383. printf("[1] Modify User Info \n");
  1384. printf("[2] Browse All Products \n");
  1385. printf("[3] Browse Products by Category \n");
  1386. printf("[4] Browse Products on Sale \n");
  1387. if (pUsers->outstanding > 0);
  1388. printf("[5] Add to Cart \n");
  1389. if (pUsers->cart)
  1390. printf("[6] View Cart \n");
  1391. printf("[7] Check Out \n");
  1392. printf("[8] Edit Cart Items \n");
  1393. printf("[0] Return to Main Menu \n");
  1394. printf("Input: ");
  1395. scanf("%d%c", &choice, &cDump);
  1396.  
  1397. switch (choice){
  1398. case 1: do {
  1399. modifyUserInfo (pUsers, &pUsers->info);
  1400. printf("Press [0] to Return to Shopper Menu \n");
  1401. printf("Input: ");
  1402. scanf("%d%c", &exit, &cDump);
  1403. }while (exit==1);
  1404. //view locked
  1405. break;
  1406. case 2: do {
  1407.  
  1408. printf("Browsing All Products \n");
  1409. pRun = pStock;
  1410. printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
  1411. while (pRun != NULL && page < 20){
  1412. if ((*pRun).pStockInfo.quantityavailable > 1){
  1413. printf("%s %s %s %s %d %d %f %f \n",
  1414. (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
  1415. }
  1416. pRun = pRun->pNext;
  1417. page++;
  1418. }
  1419. page = 0;
  1420. printf("Press [N] return to main menu or ENTER to view next page. \n");
  1421. scanf("%c%c", &cExit, &cDump);
  1422. }while (cExit=='\0');
  1423.  
  1424.  
  1425. break;
  1426. case 3: do {
  1427.  
  1428. printf("Input the category");
  1429. printf("Input: ");scanf("%s%c",TempCategory, &cDump);
  1430.  
  1431. searchStock (pStock, TempCategory);
  1432.  
  1433. if (searchStock (pStock, TempCategory)==NULL)
  1434. printf("Category not found \n");
  1435.  
  1436. else if (searchStock (pStock, TempCategory)!=NULL){
  1437.  
  1438. printf("Browsing Products by Category \n");
  1439. pRun = pStock;
  1440.  
  1441. printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
  1442. while (pRun != NULL){
  1443. if (strcmp(pRun->category,TempCategory)==0 && (*pRun).pStockInfo.quantityavailable>1){
  1444. printf("%s %s %s %s %d %d %f %f \n",
  1445. (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
  1446. }
  1447. pRun = pRun->pNext;
  1448.  
  1449. }
  1450. }
  1451. printf("Press [0] to Return to Shopper Menu \n");
  1452. printf("Input: ");
  1453. scanf("%d%c", &exit, &cDump);
  1454. }while (exit==1);
  1455.  
  1456. break;
  1457. case 4: do {
  1458.  
  1459. printf("Browsing Products on Sale \n");
  1460.  
  1461. pRun = pStock;
  1462.  
  1463. while (pRun != NULL)
  1464. {
  1465. if ((*pRun).pStockInfo.discountrate > 0){
  1466. printf("%s %s %s %s %d %d %f %f \n",
  1467. (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
  1468. }
  1469. pRun = pRun->pNext;
  1470. }
  1471.  
  1472.  
  1473. printf("Press [0] to Return to Shopper Menu \n");
  1474. printf("Input: ");
  1475. scanf("%d%c", &exit, &cDump);
  1476. }while (exit==1);
  1477.  
  1478. break;
  1479. case 5: do {
  1480.  
  1481. printf("Input the product code of the item: \n");
  1482. printf("Press [0] to Return to Shopper Menu \n");
  1483. printf("Input: ");
  1484. scanf("%d%c", &exit, &cDump);
  1485. }while (exit==1);
  1486.  
  1487. break;
  1488. case 6: do {
  1489.  
  1490. printf("Viewing Cart \n");
  1491. printf("Press [0] to Return to Shopper Menu \n");
  1492. printf("Input: ");
  1493. scanf("%d%c", &exit, &cDump);
  1494. }while (exit==1);
  1495.  
  1496. break;
  1497. case 7: do {
  1498.  
  1499.  
  1500. printf("Press [0] to Return to Shopper Menu \n");
  1501. printf("Input: ");
  1502. scanf("%d%c", &exit, &cDump);
  1503. }while (exit==1);
  1504.  
  1505. break;
  1506. case 8: do {
  1507.  
  1508. printf("Press [0] to Return to Shopper Menu \n");
  1509. printf("Input: ");
  1510. scanf("%d%c", &exit, &cDump);
  1511. }while (exit==1);
  1512.  
  1513. break;
  1514. default: printf("Your account has been successfully logged out. \n");
  1515. pUsers->nLoggedin = 0;
  1516. choice = 0;
  1517. break;
  1518. }
  1519.  
  1520.  
  1521. }while (choice > 0 && choice < 9);
  1522.  
  1523. }
  1524.  
  1525. //Function Name: AdminMenu
  1526. //Function Required Input Parameters: N/A
  1527. //Function Expected Return Data: 0 if the administrator wishes to shutdown the kiosk
  1528. //Function Description and or Algorithim: Displays the administrator menu so the administrator can access the aspects of the kiosk.
  1529. int AdminMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
  1530. {
  1531. int choice, exit = 1;
  1532. char cDump;
  1533.  
  1534. do {
  1535.  
  1536. printf("ADMINISTRATOR MENU \n");
  1537. printf("[1] Manage Accounts Menu \n");
  1538. printf("[2] Manage Stocks Menu \n");
  1539. printf("[3] Prepare Delivery Receipt \n");
  1540. printf("[4] Shutdown Kiosk \n");
  1541. printf("[5] Log Out \n");
  1542. printf("Input: ");
  1543. scanf("%d%c", &choice, &cDump);
  1544.  
  1545. switch (choice){
  1546. case 1: do {
  1547. AdminManageAccounts (pUsers, &pUsers->info);
  1548. printf("Press [0] to return to Administrator Menu: ");
  1549. scanf("%d", &exit);
  1550. }while (exit==1);
  1551. break;
  1552. case 2: do {
  1553. AdminManageStocks (pUsers, pStock, pNewStock, pEnd);
  1554. printf("Press [0] to return to Administrator Menu: ");
  1555. scanf("%d", &exit);
  1556. }while (exit==1);
  1557. break;
  1558. case 3: do {
  1559. AdminPrepareDelivery (pUsers, pStock, pNewStock, &pUsers->info);
  1560. printf("Press [0] to return to Administrator Menu: ");
  1561. scanf("%d", &exit);
  1562. }while (exit==1);
  1563. break;
  1564. case 4:
  1565. printf("Kiosk Shutdown. \n");
  1566. choice = 0;
  1567. return 0;
  1568. break;
  1569.  
  1570. case 5:
  1571. pUsers->nLoggedin == 0;
  1572. printf("Your account has been successfully logged out. \n");
  1573.  
  1574. break;
  1575.  
  1576. default:
  1577. break;
  1578.  
  1579. }
  1580.  
  1581. }while (choice > 0 && choice < 5 && choice != 4);
  1582. }
  1583.  
  1584. //Function Name: menu
  1585. //Function Required Input Parameters: N/A
  1586. //Function Expected Return Data: 0 if the user wishes to shutdown kiosk
  1587. //Function Description and or Algorithim: Displays the sign up and login for the user to access.
  1588. void menu (userType *pUsers, userType *pNew, userType *pLast, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
  1589. {
  1590. int choice=0;
  1591. char cDump;
  1592. int exit;
  1593.  
  1594. pUsers = NULL;
  1595. pNew = NULL;
  1596. pLast = NULL;
  1597.  
  1598. ptrUser pRun, pTrail;
  1599.  
  1600. do {
  1601. printf("MAIN MENU \n");
  1602. printf("[1] Sign Up \n");
  1603. printf("[2] Log In \n");
  1604. //printf("[0] Shutdown Kiosk \n");
  1605. printf("Choice: ");
  1606. scanf("%d%c", &choice,&cDump);
  1607.  
  1608. if (choice > 2 || choice < 0 ){
  1609.  
  1610. printf("INVALID INPUT \n \n");
  1611. menu (pUsers, pNew, pLast, pStock, pNewStock, pEnd);
  1612. }
  1613.  
  1614. switch (choice){
  1615. case 1:
  1616. do{
  1617. pNew = malloc(sizeof(userType));
  1618.  
  1619. signUp(pNew, pUsers);
  1620. pNew -> pNext = NULL;
  1621.  
  1622. if (pUsers == NULL) //if list is empty
  1623. pUsers = pNew;
  1624.  
  1625. else if (strcmp(pUsers -> username, pNew -> username) > 0){ //conect as first node
  1626.  
  1627. pNew -> pNext = pUsers;
  1628. pUsers = pNew;
  1629.  
  1630. }
  1631.  
  1632. else { //modifying middle of list
  1633.  
  1634. pRun = pUsers;
  1635.  
  1636. while (pRun != NULL && strcmp(pRun -> username, pNew -> username) < 0){
  1637.  
  1638. pTrail = pRun;
  1639. pRun = pRun -> pNext;
  1640.  
  1641. }
  1642.  
  1643. pTrail -> pNext = pNew;
  1644. pNew -> pNext = pRun;
  1645. }
  1646.  
  1647. getUserInfo (&pUsers->info);
  1648.  
  1649. printf("Press [0] to create a new user or [1] to return to main menu: ");
  1650. scanf("%d%c", &exit, &cDump);
  1651.  
  1652. if(exit>1||exit<0)
  1653. {
  1654. printf("Invalid input! returning you to main menu");
  1655. exit = 1;
  1656.  
  1657. }
  1658.  
  1659. }while(exit==0);
  1660. break;
  1661.  
  1662. case 2:
  1663.  
  1664.  
  1665. if (signIn(pUsers, &pUsers->info , pNew, pLast)==1)
  1666. ShopperMenu (pUsers, pNew, pLast, &pUsers->info, pStock);
  1667. else if (signIn(pUsers, &pUsers->info , pNew, pLast)==2)
  1668. if (AdminMenu (pUsers, pNew, pLast, &pUsers->info, pStock, pNewStock, pEnd)==0)
  1669. choice = 0;
  1670. break;
  1671.  
  1672. default:freeAll(&pUsers);
  1673.  
  1674. break;
  1675. }
  1676.  
  1677. }while (choice == 1||choice == 2);
  1678.  
  1679. freeAll(&pUsers);
  1680.  
  1681. }
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689. int main ()
  1690. {
  1691. categoryType *pFirst,
  1692. *pNewStock,
  1693. *pEnd;
  1694.  
  1695. userType *pUsers,
  1696. *pNew,
  1697. *pLast;
  1698. ptrUser pRun, pTrail;
  1699. categoryType aCategories[10];
  1700.  
  1701. menu (pUsers, pNew, pLast, pFirst, pNewStock, pEnd);
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707. //displayAll(pUsers);
  1708.  
  1709.  
  1710. return 0;
  1711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement