Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************************
- This is to certify that this project is my own work,
- based on my personal efforts in studying and applying the concepts learned.
- I have constructed the functions and their respective algorithms and corresponding code by myself.
- The program was run, tested, and debugged by my own efforts. I further certify that I have not
- copied in part or whole or otherwise plagiarized the work of other students and/or persons.
- PINEDA, Lucia Corazon L., DLSU ID# 11610697
- ***********************************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_CART 100
- typedef char string15[16];
- typedef char string20[21];
- typedef char string50[51];
- typedef char string8[9];
- typedef struct{
- string20 first,
- middle,
- last;
- } nameType;
- typedef struct{
- nameType name;
- string50 address;
- }userInfoType;
- typedef struct{
- string8 code;
- int qty;
- }prodBoughtType;
- typedef prodBoughtType arrBought[MAX_CART];
- struct userTag{
- string15 username,
- password;
- userInfoType info;
- char type;
- float creditlimit,
- outstanding;
- arrBought cart;
- int nItems,
- isLocked;
- struct userTag *pNext;
- };
- typedef struct userTag userType;
- typedef userType * ptrUser;
- struct productListTag{
- string15 supplier,
- product;
- int qtyAvailable;
- float purPrice,
- unitSellPrice,
- discRate;
- int qtySold;
- string8 prodCode;
- };
- struct stockTag{
- string15 category;
- struct productListTag prodList;
- struct stockTag *pNext;
- };
- typedef struct stockTag stockType;
- typedef stockType * ptrStock;
- ///////FUNCTIONS:
- /*function numDigits counts the number of digits of an integer
- @param: Number - input integer
- @return: digits - number of of digits of the integer
- */
- int numDigits(int number){
- int digits=0;
- if(number<0)
- digits=1;
- while(number){
- number/=10;
- digits++;
- }
- return digits;
- }
- /*Function freeAll frees all the User structures of their data and gets rid of all dangling pointers.
- @param: *pFirst - structure with data of current user
- */
- void freeAll(ptrUser *pFirst){
- ptrUser pDel;
- while(*pFirst!=NULL){
- pDel=*pFirst;
- *pFirst=(*pFirst)->pNext;
- free(pDel);
- }
- }
- /*Function freeAllStocks Frees all the Stock structures of their data and gets rid of all dangling pointers.
- @param: *pFirst - structure with data of current stock
- */
- void freeAllStocks(ptrStock *pFirst){
- ptrStock pDel;
- while(*pFirst!=NULL){
- pDel=*pFirst;
- *pFirst=(*pFirst)->pNext;
- free(pDel);
- }
- }
- /*Function getUserInfo asks user to input their information, which consists of name and address
- @param: *pInfo - structure of “User Information” within the bigger structure with data of current user
- */
- void getUserInfo(userInfoType *pInfo){
- getchar();
- printf("[Name]\n");
- printf("First name: ");
- fgets(pInfo->name.first, 21, stdin);
- printf("Middle name: ");
- fgets(pInfo->name.middle, 21, stdin);
- printf("Last name: ");
- fgets(pInfo->name.last, 21, stdin);
- printf("Enter address: ");
- fgets(pInfo->address, 51, stdin);
- //Removes the '\n' because fgets takes the enter key and adds it to the string
- pInfo->address[strlen(pInfo->address)-1]='\0';
- pInfo->name.first[strlen(pInfo->name.first)-1]='\0';
- pInfo->name.middle[strlen(pInfo->name.middle)-1]='\0';
- pInfo->name.last[strlen(pInfo->name.last)-1]='\0';
- }
- /*Function manageAccounts Displays the Manage Account Menu’s options (view locked accounts,
- unlock specific account, unlock all locked accounts, unlock all locked accounts, view accounts
- with outstanding balance, and return to administrator menu) and lets the user choose an option.
- @param: *pUser - structure that holds the information of the current user
- */
- void viewLocked(userType *pCurrent){
- printf("\n[LOCKED ACCOUNTS]\n");
- while(pCurrent!=NULL){
- if(pCurrent->isLocked==1)
- printf("%s\n", pCurrent->username);
- pCurrent=pCurrent->pNext;
- }
- }
- void manageAccounts(userType *pUser){
- userType *pCurrent;
- int opt=0;
- char cDump;
- string15 username;
- do{
- printf("\n------Manage Accounts Menu------\n");
- printf("1 - View Locked Accounts\n");
- printf("2 - Unlock Specific Account\n");
- printf("3 - Unlock All Locked Accounts\n");
- printf("4 - View Accounts with Outstanding Balance\n");
- printf("5 - Return to Administrator Menu\n\n");
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: viewLocked(pUser);
- break;
- case 2: viewLocked(pUser);
- printf("Input username of account to unlock: ");
- scanf("%s%c", username, &cDump);
- pCurrent=pUser;
- while(pCurrent!=NULL){
- if(pCurrent->isLocked==1 && strcmp(pCurrent->username, username)==0)
- pCurrent->isLocked=0;
- pCurrent=pCurrent->pNext;
- }
- printf("The account of %s has been unlocked.\n", username);
- break;
- case 3: viewLocked(pUser);
- pCurrent=pUser;
- while(pCurrent!=NULL){
- if(pCurrent->isLocked==1)
- pCurrent->isLocked=0;
- pCurrent=pCurrent->pNext;
- }
- printf("All locked accounts have been unlocked.\n");
- break;
- case 4: pCurrent=pUser;
- printf("\n[ACCOUNTS WITH OUTSTANDING BALANCE]\n");
- while(pCurrent!=NULL){
- if((pCurrent->type=='s' || pCurrent->type=='S') && pCurrent->outstanding>0.00){
- printf("username: %s\n", pCurrent->username);
- printf("full name: %s %s %s\n", pCurrent->info.name.first, pCurrent->info.name.middle, pCurrent->info.name.last);
- printf("Outstanding Balance: P %.2f\n", pCurrent->outstanding);
- }
- pCurrent=pCurrent->pNext;
- }
- break;
- case 5: break;
- }
- printf("\n");
- }while(opt!=5);
- }
- /*Function checkStock checks if the input code was already used in a previous stock.
- @param: category - input category
- *pStock - structure that holds all the stock information
- */
- int checkStock(string15 category, stockType *pStock){
- int check=1;
- stockType *pOrig = pStock;
- while(pOrig!=NULL)
- {
- if(strcmp(category, pOrig->category)==0)
- {
- check=0;
- pOrig=NULL;
- }
- else
- pOrig=pOrig->pNext;
- }
- return check;
- }
- int checkProd(string15 product, stockType *pStock){
- int check=1;
- stockType *pOrig = pStock;
- while(pOrig!=NULL)
- {
- if(strcmp(product, pOrig->prodList.product)==0)
- {
- check=0;
- pOrig=NULL;
- }
- else
- pOrig=pOrig->pNext;
- }
- return check;
- }
- void displayAllStocks(ptrStock pStocks){
- while(pStocks!=NULL){
- printf("\n%s\n", pStocks->category);
- pStocks=pStocks->pNext;
- }
- }
- /*Function addNewStock will add a new stock to the current list of stocks by asking stock information
- @param: *pStock - structure with information of current stock
- *pOriginal - structure with information of all stocks*/
- void addNewStock(stockType *pStock, stockType *pOriginal, int *categoryCtr){
- stockType *pCurrent=NULL,
- *pNew;
- string15 category,
- supplier,
- product;
- int unique=0,
- unique1=0,
- unique2=0,
- i=0,
- newStock=0,
- randomNum=0,
- uniqueProd=0;
- char cDump;
- getchar();
- printf("[ADD NEW STOCK]\n");
- do{
- do{
- printf("Enter category: ");
- scanf("%s%c", &category, &cDump);
- }while(strlen(category)<3 || strlen(category)>15);
- if(strlen(category)>=3 && strlen(category)<=15){
- pCurrent=pOriginal;
- unique=checkStock(category, pOriginal);
- if(unique==1)
- { //NEW CATEGORY!!!
- (*categoryCtr)++;
- printf("\nNew Category! Category number %d\n", *categoryCtr);
- }
- if(unique!=1) //NOT A NEW CATEGORY
- printf("Category already exists.\n");
- strcpy(pStock->category, category);
- printf("[Product List]\n");
- do{
- do{
- printf("Enter supplier: ");
- fgets(supplier, 16, stdin);
- supplier[strlen(supplier)-1]='\0';
- }while(strlen(supplier)>15);
- do{
- printf("Enter product: ");
- fgets(product, 16, stdin);
- product[strlen(product)-1]='\0';
- }while(strlen(product)>15);
- if(strlen(product)<=15){
- uniqueProd=checkProd(product, pOriginal);
- if(uniqueProd==1)
- {
- strcpy(pStock->prodList.supplier, supplier);
- strcpy(pStock->prodList.product, product);
- }
- if(uniqueProd!=1)
- {
- printf("Product already exists.\n");
- }
- }
- }while(uniqueProd!=1);
- uniqueProd=0;
- printf("Enter quantity available: ");
- scanf("%d", &pStock->prodList.qtyAvailable);
- printf("Enter purchase price: ");
- scanf("%f", &pStock->prodList.purPrice);
- printf("Enter unit selling price: ");
- scanf("%f", &pStock->prodList.unitSellPrice);
- printf("Enter discount rate: ");
- scanf("%f", &pStock->prodList.discRate);
- pStock->prodList.qtySold=0;
- pStock->prodList.prodCode[0]=category[0];
- pStock->prodList.prodCode[1]=supplier[0];
- pStock->prodList.prodCode[2]=product[0];
- i=1;
- while(i<=5){
- randomNum = rand()%58;
- if(randomNum>47 && randomNum<58){
- pStock->prodList.prodCode[(i+2)]=randomNum;
- i++;
- }
- }
- pStock->prodList.prodCode[8]='\0';
- printf("CHEEEECK\n");
- }
- }while(strlen(category)<3 || strlen(category)>15);
- printf("CHECKING OUTSIDE DA LOOOOP\n");
- }
- /*Function viewStocks displays all the stock information for the administrator, and the products for the shoppers
- @param: *pStocks - structure that holds all the stock information
- opt- number that shows if the user is a shopper or administrator
- */
- void viewStocks(ptrStock pStocks, int opt){
- int i=0,
- page=1,
- length,
- stockNum;
- string15 categoryInput;
- char nextPage;
- stockType *pCurrent;
- string15 space=" ",
- space2=" ",
- space3=" ";
- char space4[10]=" ";
- char space5[5]=" ";
- char space6[9]=" ";
- char space7[8]=" ";
- stockNum=stockCount(pStocks);
- if(opt==1){
- printf("\n[VIEW STOCKS]\n");
- printf("Category Supplier Product Product Qty Qty Purchase Selling Discount\n");
- printf(" Code Available Sold Price Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- while(i<20 && pCurrent!=NULL){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- pCurrent=pCurrent->pNext;
- }
- printf("\n\npage %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- if(opt==2){
- printf("Enter a category: ");
- scanf("%s", categoryInput);
- printf("\n[VIEW STOCKS BY CATEGORY]\n");
- printf("Category Supplier Product Product Qty Qty Purchase Selling Discount\n");
- printf(" Code Available Sold Price Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- while(i<20 && pCurrent!=NULL){
- if(strcmp(categoryInput, pCurrent->category)==0){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- }
- pCurrent=pCurrent->pNext;
- }
- printf("\n\npage %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- if(opt==3){
- printf("Enter a category: ");
- scanf("%s", categoryInput);
- printf("\n[VIEW STOCKS TO REORDER]\n");
- printf("Category Supplier Product Product Qty Qty Purchase Selling Discount\n");
- printf(" Code Available Sold Price Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- while(i<20 && pCurrent!=NULL){
- if(pCurrent->prodList.qtyAvailable<=5){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- }
- pCurrent=pCurrent->pNext;
- }
- printf("\n\npage %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- if(opt==4){
- printf("\n[BROWSE ALL PRODUCTS]\n");
- printf("Category Brand Product Product Qty Qty Purchase Unit Discount\n");
- printf(" Code Available Sold Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- while(i<20 && pCurrent!=NULL){
- if(pCurrent->prodList.qtyAvailable>0){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- }
- pCurrent=pCurrent->pNext;
- }
- printf("\n\n page %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- if(opt==5){
- printf("\n[BROWSE PRODUCTS BY CATEGORIES]\n");
- printf("Category Brand Product Product Qty Qty Purchase Unit Discount\n");
- printf(" Code Available Sold Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- printf("Enter category: ");
- scanf("%s", categoryInput);
- while(i<20 && pCurrent!=NULL){
- if(pCurrent->prodList.qtyAvailable>0 && strcmp(categoryInput, pCurrent->category)==0){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- }
- pCurrent=pCurrent->pNext;
- }
- printf("\n\n page %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- if(opt==6){
- printf("\n[BROWSE PRODUCTS ON SALE]\n");
- printf("Category Brand Product Product Qty Qty Purchase Unit Discount\n");
- printf(" Code Available Sold Price Rate\n");
- pCurrent=pStocks;
- i=1;
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- while(i<20 && pCurrent!=NULL){
- if(pCurrent->prodList.qtyAvailable>0 && pCurrent->prodList.discRate>0){
- printf("%s", pCurrent->category);
- space[(15-strlen(pCurrent->category))]='\0';
- printf("%s", space);
- printf("%s", pCurrent->prodList.supplier);
- space2[(15-strlen(pCurrent->prodList.supplier))]='\0';
- printf("%s", space2);
- printf("%s ", pCurrent->prodList.prodCode);
- printf("%s", pCurrent->prodList.product);
- space3[(15-strlen(pCurrent->prodList.product))]='\0';
- printf("%s", space3);
- printf("%d", pCurrent->prodList.qtyAvailable);
- space4[(9-numDigits(pCurrent->prodList.qtyAvailable))]='\0';
- printf("%s ", space4);
- printf("%d", pCurrent->prodList.qtySold);
- space5[(4-numDigits(pCurrent->prodList.qtySold))]='\0';
- printf("%s", space5);
- printf("%.2f", pCurrent->prodList.purPrice);
- space6[(6-numDigits(pCurrent->prodList.purPrice))]='\0';
- printf("%s", space6);
- printf("%.2f", pCurrent->prodList.unitSellPrice);
- space7[(5-numDigits(pCurrent->prodList.unitSellPrice))]='\0';
- printf("%s", space7);
- printf("%.1f\n\n", pCurrent->prodList.discRate);
- i++;
- }
- pCurrent=pCurrent->pNext;
- }
- printf("\n\n page %d of %d \n\n", page, stockNum);
- page++;
- scanf("%c", &nextPage);
- }
- }
- /*Function checkProdCode checks if the input product code was already used in a previous stock.
- @param: code - input product code
- *pStock - structure that holds all the stock information
- @return: check- integer (0 if product code isn't unique, 1 if it is)
- */
- int checkProdCode(string8 code, stockType *pStock){
- int check=1;
- stockType *pOrig = pStock;
- while(pOrig!=NULL)
- {
- if(strcmp(code, pOrig->prodList.prodCode)==0)
- {
- check=0;
- pOrig=NULL;
- }
- else
- pOrig=pOrig->pNext;
- }
- return check;
- }
- /*Function modifyStockInfo Asks the user if they want to change the stock information
- @param: *pStock - structure that holds all the stocks
- */
- void modifyStockInfo(stockType *pStock){ //first displays all && then if product code is not found, reurn to managestocksmenu
- string8 code,pTemp;
- stockType *pCurrent=NULL;
- int opt=0,
- i=0,
- j=0,
- k=0,
- randomNum=0,
- found=0;
- char cDump;
- viewStocks(pStock, 1);
- printf("\n\nEnter product code of item to be modified: ");
- scanf("%s%c", code, &cDump);
- pCurrent=pStock;
- while(pCurrent!=NULL && found==0){
- if(strcmp(pCurrent->prodList.prodCode, code)==0)
- found=1;
- if(found==0)
- pCurrent=pCurrent->pNext;
- }
- if(found==1){
- do{
- printf("\n[MODIFY STOCK INFO]\n");
- printf("1 - Modify Category\n");
- printf("2 - Modify Supplier\n");
- printf("3 - Modify Product\n");
- printf("4 - Modify Purchase Price\n");
- printf("5 - Modify Selling Price\n");
- printf("6 - Modify Discount\n");
- printf("7 - Finish Modification of Product <Product Code>\n\n");
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: do{
- printf("New category: ");
- scanf("%s%c", pCurrent->category, &cDump);
- }while(strlen(pCurrent->category)<3 || strlen(pCurrent->category)>15);
- break;
- case 2: getchar();
- do{
- printf("New supplier: ");
- fgets(pCurrent->prodList.supplier, 16, stdin);
- pCurrent->prodList.supplier[strlen(pCurrent->prodList.supplier)-1]='\0';
- }while(strlen(pCurrent->prodList.supplier)>15);
- break;
- case 3: getchar();
- do{
- printf("New product: ");
- fgets(pCurrent->prodList.product, 16, stdin);
- pCurrent->prodList.product[strlen(pCurrent->prodList.product)-1]='\0';
- }while(strlen(pCurrent->prodList.product)>15);
- break;
- case 4: printf("New purchase price: ");
- scanf("%f", &pCurrent->prodList.purPrice);
- break;
- case 5: printf("New unit selling price: ");
- scanf("%f", &pCurrent->prodList.unitSellPrice);
- break;
- case 6: printf("New discount rate: ");
- scanf("%f", &pCurrent->prodList.discRate);
- break;
- case 7: strcpy(pTemp,pCurrent->prodList.prodCode);
- if(pCurrent->prodList.prodCode[0]!=pCurrent->category[0])
- pTemp[0]=pCurrent->category[0];
- if(pCurrent->prodList.prodCode[1]!=pCurrent->prodList.supplier[0])
- pTemp[1]=pCurrent->prodList.supplier[0];
- if(pCurrent->prodList.prodCode[2]!=pCurrent->prodList.product[0])
- pTemp[2]=pCurrent->prodList.product[0];
- printf("CHECK PROD CODE: %d\n", checkProdCode(pTemp, pStock));
- if(checkProdCode(pTemp, pStock)!=1){
- i=1;
- while(i<=5){
- randomNum = rand()%58;
- if(randomNum>47 && randomNum<58){
- pTemp[(i+2)]=randomNum;
- i++;
- }
- }
- pTemp[8]='\0';
- }
- strcpy(pCurrent->prodList.prodCode,pTemp);
- printf("Product code is now %s\n", pCurrent->prodList.prodCode);
- break;
- }
- }while(opt!=7);
- }
- else
- printf("Invalid product code");
- }
- /*Function restock Asks the user which product’s number of items
- to they want to modify, then allows them to add to it
- @param: *pStock - structure that holds the information of all the stocks
- */
- void restock(stockType *pStock){
- string8 code;
- stockType *pCurrent=NULL;
- int add=0,
- found=0;
- char cDump;
- viewStocks(pStock, 1);
- printf("\n\nEnter product code of item to be modified: ");
- scanf("%s%c", code, &cDump);
- pCurrent=pStock;
- while(pCurrent!=NULL && found==0){
- if(strcmp(pCurrent->prodList.prodCode, code)==0)
- found=1;
- if(found==0)
- pCurrent=pCurrent->pNext;
- }
- if(found==1){
- printf("Additional quantity for this available items: ");
- scanf("%d", &add);
- pCurrent->prodList.qtyAvailable=pCurrent->prodList.qtyAvailable+add;
- }
- else
- printf("\nLast input product Code not found: Not restocked.\n");
- }
- /*Function stockCount counts the number of stocks
- @param: pStocks - structure that holds all the stock information
- @return: count - number of stocks
- */
- int stockCount(ptrStock pStocks){
- int count=0;
- while(pStocks!=NULL){
- count++;
- pStocks=pStocks->pNext;
- }
- return count;
- }
- void saveStocksToTextFile(ptrStock pFirst){
- FILE *pText;
- string20 strName;
- if(pFirst == NULL)
- printf("Nothing to save.\n");
- else{
- printf("Enter filename: ");
- scanf("%s", strName);
- pText=fopen(strName, "wt");
- if(pText!=NULL){
- while(pFirst!=NULL){
- fprintf(pText, "%s %s %s\n%d %.2f %s\n%.2f&%.1f %d\n\n",
- pFirst->category, pFirst->prodList.prodCode, pFirst->prodList.product, pFirst->prodList.qtyAvailable,
- pFirst->prodList.purPrice, pFirst->prodList.supplier, pFirst->prodList.unitSellPrice, pFirst->prodList.discRate,
- pFirst->prodList.qtySold);
- pFirst=pFirst->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file.\n");
- }
- }
- /*Function manageStocks Displays the Manage Stocks Menu’s
- Options (add new stock, view all stocks, view stocks by category, view stocks to reorder, modify stock info,
- restock, save inventory, update inventory from file)
- and lets the user choose an option.
- @param: *pStocks - structure that holds the information of all stocks
- *categoryCtr - number of unique categories
- */
- void manageStocks(ptrStock pStocks, int *categoryCtr){
- int opt=0,
- choose=0;
- char cDump;
- ptrStock pNew=NULL,
- pRun=NULL,
- pTrail=NULL;
- string15 category;
- do{
- printf("\n------MANAGE STOCKS MENU------\n");
- printf("1 - Add New Stock\n");
- printf("2 - View All Stocks\n");
- printf("3 - View Stocks by Category\n");
- printf("4 - View Stocks to Reorder\n");
- printf("5 - Modify Stock Info\n");
- printf("6 - Restock\n");
- printf("7 - Save Inventory\n");
- printf("8 - Update Inventory from File\n");
- printf("9 - Return to Admin Menu\n");
- printf("\nCHECK: \n\n\n");
- displayAllStocks(pStocks);
- printf("\nCHECK: New Category! Category number %d\n", *categoryCtr);
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: if(*categoryCtr<10){ //counts the number of categories (max. 10)
- pNew=malloc(sizeof(stockType));
- pNew->pNext=NULL;
- if(pStocks==NULL){
- addNewStock(pNew, NULL, categoryCtr);
- pStocks=pNew;
- }
- else if(strcmp(pStocks->category, pNew->category)<0){ //connect at first node
- addNewStock(pNew, pStocks, categoryCtr);
- pNew->pNext=pStocks;
- pStocks=pNew;
- }
- else{
- addNewStock(pNew, pStocks, categoryCtr);
- pRun=pStocks;
- while(pRun != NULL && strcmp(pRun->category, pNew->category)>0){ //modifying middle of the list
- pTrail=pRun;
- pRun=pRun->pNext;
- }
- pTrail->pNext=pNew;
- pNew->pNext=pRun;
- }
- }
- else
- printf("\nMAXIMUM AMOUNT OF CATEGORIES REACHED. Cannot add any more.\n");
- break;
- case 2: viewStocks(pStocks, 1);
- break;
- case 3: viewStocks(pStocks, 2);
- break;
- case 4: viewStocks(pStocks, 3);
- break;
- case 5: modifyStockInfo(pStocks);
- break;
- case 6: restock(pStocks);
- break;
- case 7: saveStocksToTextFile(pStocks);
- break;
- }
- }while(opt!=9);
- }
- void saveReceiptToTextFile(ptrUser pFirst, ptrStock pStock){
- FILE *pText;
- string20 strName;
- int items=0,
- i=0;
- items=pFirst->nItems;
- if(pFirst == NULL)
- printf("Nothing to save.\n");
- else{
- printf("Enter filename: ");
- scanf("%s", strName);
- pText=fopen(strName, "wt");
- if(pText!=NULL){
- while(pFirst!=NULL){
- fprintf(pText, "%s %d\n", pFirst->username, pFirst->nItems);
- while(items>0){
- fprintf(pText, "%d %s ", pFirst->cart[i].qty, pFirst->cart[i].code);
- while(pStock!=NULL){
- if(strcmp(pFirst->cart[i].code, pStock->prodList.prodCode)==0)
- fprintf(pText, "%s\n", pStock->prodList.product);
- else
- pStock=pStock->pNext;
- }
- fprintf(pText, "@%.2f&%.1f\n", pStock->prodList.unitSellPrice, pStock->prodList.discRate);
- i++;
- items--;
- }
- pFirst=pFirst->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file.\n");
- }
- }
- void receipt(userType *pUser, stockType *pStock){
- int items=0,
- i=0,
- itemNum=0;
- float itemSubtotal=0.0,
- totalDisc=0.0,
- billAmt=0.0;
- items=pUser->nItems;
- printf("DELIVERY RECEIPT:\n");
- printf("User ID: %s\n", pUser->username);
- printf("Customer Name: %s, %s %s\n", pUser->info.name.last, pUser->info.name.first, pUser->info.name.middle);
- printf("Delivery Address: %s\n", pUser->info.address);
- printf("Product Product Quantity Unit Price Total Price Item\n");
- printf("Code Subtotal\n");
- while(items>0){
- printf("%s", pUser->cart[i].code);
- while(pStock!=NULL){
- if(strcmp(pUser->cart[i].code, pStock->prodList.prodCode)==0)
- printf("%s", pStock->prodList.product);
- else
- pStock=pStock->pNext;
- }
- printf("%d", pUser->cart[i].qty);
- printf("P %.2f", pStock->prodList.unitSellPrice);
- printf("P %.2f", (pStock->prodList.unitSellPrice)*(pUser->cart[i].qty));
- printf("- %.1f", pStock->prodList.discRate);
- itemSubtotal=pStock->prodList.unitSellPrice - (((pStock->prodList.discRate)/100)*pUser->cart[i].qty);
- printf("P %.2f", itemSubtotal);
- itemNum=itemNum+pUser->cart[i].qty;
- totalDisc=totalDisc+pStock->prodList.discRate;
- billAmt=billAmt+itemSubtotal;
- i++;
- items--;
- }
- printf("Number of items: %d\n", itemNum);
- printf("Total Discount: Php %.1f\n", totalDisc);
- printf("Bill Amount: Php %.2f\n", billAmt);
- printf("Total Outstanding: Php %.2f\n", billAmt+pUser->outstanding);
- saveReceiptToTextFile(pUser, pStock);
- }
- /*Function adminMenu displays the administrator menu and its options once an administrator has logged in
- Allows the user to choose an option.
- @param: *pUser - structure with information of current user
- *shutdown - option to shutdown (initialized to 0 originally)
- pStock - structure that holds all stock information
- *categoryCtr - number of unique categories
- */
- void adminMenu(userType *pUser, int *shutdown, ptrStock pStock, int *categoryCtr){
- int opt;
- do{
- printf("\n------ADMINISTRATOR MENU------\n");
- printf("1 - Manage Accounts Menu\n");
- printf("2 - Manage Stocks Menu\n");
- printf("3 - Prepare Delivery Receipt\n");
- printf("4 - Shutdown Kiosk\n");
- printf("5 - Log Out\n\n");
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: manageAccounts(pUser);
- break;
- case 2: manageStocks(pStock, categoryCtr);
- break;
- case 3:
- break;
- case 4: *shutdown=1;
- break;
- case 5: break;
- }
- }while(opt!=5 && *shutdown==0);
- }
- /*Function modifyUserInfo Asks the user if they want to change the user info (either name, address, or password).
- @param: *pUser - structure that holds all the users
- */
- void modifyUserInfo(userType *pUser){
- int opt=0,
- choose=0,
- check=0,
- i;
- char cDump;
- do{
- printf("\n[MODIFY USER INFO]\n");
- printf("1 - Change name\n");
- printf("2 - Change address\n");
- printf("3 - Change password\n");
- printf("4 - Exit\n\n");
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: printf("\n[Editing Options]\n");
- printf("1 - First name\n");
- printf("2 - Middle name\n");
- printf("3 - Last name\n\n");
- do{
- printf("Enter option to edit: ");
- scanf("%d", &choose);
- }while(choose!=1 && choose!=2 && choose!=3);
- getchar();
- switch(choose){
- case 1: printf("New first name: ");
- fgets(pUser->info.name.first, 21, stdin);
- pUser->info.name.first[strlen(pUser->info.name.first)-1]='\0';
- break;
- case 2: printf("New middle name: ");
- fgets(pUser->info.name.middle, 21, stdin);
- pUser->info.name.middle[strlen(pUser->info.name.middle)-1]='\0';
- break;
- case 3: printf("New last name: ");
- fgets(pUser->info.name.last, 21, stdin);
- pUser->info.name.last[strlen(pUser->info.name.last)-1]='\0';
- break;
- }
- printf("New name: %s %s %s\n", pUser->info.name.first, pUser->info.name.middle, pUser->info.name.last);
- break;
- case 2: getchar();
- printf("Enter new address: ");
- fgets(pUser->info.address, 51, stdin);
- //Removes the '\n' because fgets takes the enter key and adds it to the string
- pUser->info.address[strlen(pUser->info.address)-1]='\0';
- printf("New address: %s\n", pUser->info.address);
- break;
- case 3: do{
- printf("Enter new password (6-15 characters, at least one must not be a letter): ");
- scanf("%s%c", pUser->password, &cDump);
- for(i=0; i<strlen(pUser->password); i++){
- if(!(pUser->password[i]>='a' && pUser->password[i]<='z'|| pUser->password[i]>='a' && pUser->password[i]<='z'))
- check=1;
- }
- } while(check==0|| strlen(pUser->password)<6 || strlen(pUser->password)>15);
- break;
- case 4: break;
- }
- }while(opt!=4);
- }
- /*Function shopperMenu Shows the user the Shopper Menu’s options (modify user info, browse all products, browse products by category, browse products on sale,
- add to cart, view cart, check out, edit cart items settle outstanding balance, log out) and allows the user to choose an option.
- @param: *pUser - structure that holds the information of all users
- *pStock - structure that holds the information of all stocks
- */
- void shopperMenu(userType *pUser, ptrStock pStock){
- int opt=0,
- quantity=0,
- count=1,
- check=0,
- choice=1,
- i=0,
- choice2=0,
- choice3=0,
- newQty=0,
- items=0,
- itemNum=0,
- checkout=0,
- j=0,
- securityCode=0;
- float itemSubtotal=0.0,
- totalDisc=0.0,
- cartAmt=0.0,
- settle=0.0;
- char cDump;
- string8 code,
- prodCode;
- string20 cardNum;
- stockType *pOrig;
- items=pUser->nItems;
- do{
- printf("\n------SHOPPER MENU------\n");
- printf("1 - Modify User Info\n");
- printf("2 - Browse All Products\n");
- printf("3 - Browse Products by Category\n");
- printf("4 - Browse Products on Sale\n");
- if(checkout==0)
- printf("5 - Add to Cart\n");
- printf("6 - View Cart\n");
- printf("7 - Settle Outstanding Balance\n");
- printf("8 - Log Out\n\n");
- printf("Choose option: ");
- scanf("%d", &opt);
- switch(opt){
- case 1: modifyUserInfo(pUser);
- break;
- case 2: printf("CHECK!!!! %s\n", pStock->category);
- viewStocks(pStock, 4);
- break;
- case 3: viewStocks(pStock, 5);
- break;
- case 4: viewStocks(pStock, 6);
- break;
- case 5: if(pUser->outstanding<pUser->creditlimit && checkout==0){
- do{
- if(check>0){
- printf("Add another item to your cart?(1 for yes, 0 for no): ");
- scanf("%d", &choice);
- }
- if(choice==1){
- printf("Input the ff. details of product you wish to purchase:\n");
- printf("Product code: ");
- scanf("%s%c", code, &cDump);
- printf("Quantity: ");
- scanf("%d", &quantity);
- if(checkProdCode(code, pStock)==1){ //if product code is valid
- pOrig=pStock;
- while(pOrig!=NULL) //if quantity is valid
- {
- if(strcmp(code, pOrig->prodList.prodCode)==0)
- {
- if(pOrig->prodList.qtyAvailable>=quantity){
- strcpy(pUser->cart[count].code, code);
- pUser->cart[count].qty=quantity;
- count++;
- check++;
- }
- pOrig=NULL;
- }
- else
- pOrig=pOrig->pNext;
- }
- }
- else
- choice=0;
- }
- }while(count>=1 && choice!=0);
- }
- break;
- case 6: if(pUser->cart[0].qty>0){
- do{
- printf("Product Product Quantity Unit Price Total Price Item\n");
- printf("Code Subtotal\n");
- while(items>0){
- printf("%s", pUser->cart[i].code);
- while(pStock!=NULL){
- if(strcmp(pUser->cart[i].code, pStock->prodList.prodCode)==0)
- printf("%s", pStock->prodList.product);
- else
- pStock=pStock->pNext;
- }
- printf("%d", pUser->cart[i].qty);
- printf("P %.2f", pStock->prodList.unitSellPrice);
- printf("P %.2f", (pStock->prodList.unitSellPrice)*(pUser->cart[i].qty));
- printf("- %.1f", pStock->prodList.discRate);
- itemSubtotal=pStock->prodList.unitSellPrice - (((pStock->prodList.discRate)/100)*pUser->cart[i].qty);
- printf("P %.2f", itemSubtotal);
- itemNum=itemNum+pUser->cart[i].qty;
- totalDisc=totalDisc+pStock->prodList.discRate;
- cartAmt=cartAmt+itemSubtotal;
- i++;
- items--;
- }
- printf("Number of items: %d\n", itemNum);
- printf("Total Discount: Php %.1f\n", totalDisc);
- printf("Cart Amount: Php %.2f\n", cartAmt);
- ///////after the display above:
- printf("\n[Options]\n");
- printf("1 - Check out\n");
- printf("2 - Edit Cart Items\n");
- printf("3 - Back to Shopper Menu\n");
- printf("Enter option: ");
- scanf("%d", &choice2);
- switch(choice2){
- case 1: //check out
- items=pUser->nItems;
- i=0;
- while(items>0){
- while(pStock!=NULL){
- if(strcmp(pUser->cart[i].code, pStock->prodList.prodCode)==0){
- pStock->prodList.qtySold=pStock->prodList.qtySold+pUser->cart[i].qty;
- pStock->prodList.qtyAvailable=pStock->prodList.qtyAvailable-pUser->cart[i].qty;
- }
- else
- pStock=pStock->pNext;
- }
- i++;
- items--;
- }
- checkout=1;
- break;
- case 2: do{
- printf("\n[Edit Cart Item Options]\n");
- printf("1 - Remove item\n");
- printf("2 - Update quantity\n");
- printf("3 - Back to View Cart Menu\n");
- printf("Enter option: ");
- scanf("%d", &choice3);
- switch(choice3){
- case 1: printf("Enter product code to remove from cart: ");
- scanf("%s%c", prodCode, &cDump);
- //delete product code input from the cart
- items=pUser->nItems;
- i=0;
- while(items>0){
- printf("%s", pUser->cart[i].code);
- while(pStock!=NULL){
- if(strcmp(pUser->cart[i].code, pStock->prodList.prodCode)==0){
- j=i;
- while(pUser->cart[j].qty>0){
- strcpy(pUser->cart[j].code, pUser->cart[j+1].code);
- pUser->cart[j].qty=pUser->cart[j+1].qty;
- j++;
- }
- }
- else
- pStock=pStock->pNext;
- }
- items++;
- i++;
- }
- break;
- case 2: printf("Enter product code: ");
- scanf("%s%c", prodCode, &cDump);
- printf("Enter new quantity: ");
- scanf("%d", &newQty);
- //new quantity should be within limits of qty availalble
- //if new qty = 0, prod is removed from cart
- break;
- case 3: break;
- }
- }while(choice3!=3);
- break;
- case 3: break; //back to shopper menu
- }
- }while(choice2!=3);
- }
- break;
- case 7: if(pUser->outstanding>0.00){
- printf("Outstanding balance: P %.2f\n\n", pUser->outstanding);
- printf("[Credit Card Information]\n");
- printf("Card Number: ");
- scanf("%s", cardNum);
- printf("Security Code: ");
- scanf("%d", &securityCode);
- do{
- if(settle>pUser->outstanding)
- printf("Amount to settle must be at most equal to the outstanding balance, or less.\n");
- printf("Enter amount to settle:");
- scanf("%f", &settle);
- }while(settle>pUser->outstanding);
- printf("Payment successful!\n");
- }
- break;
- case 8: break;
- }
- }while(opt!=8);
- }
- /*Function checkUsername Checks if the input code was already used in a previous stock.
- @param: category - input category
- *pStock = structure that holds all the stock information
- */
- int checkUsername(string15 username, userType *pUser)
- {
- int check=1;
- userType *pOrig = pUser;
- while(pOrig!=NULL)
- {
- if(strcmp(username, pOrig->username)==0)
- {
- check=0;
- pOrig=NULL;
- }
- else
- pOrig=pOrig->pNext;
- }
- return check;
- }
- /*Function signUp Adds a new user to the current list of users by asking for user information.
- @param: *pUser - structure that holds the information of the current user
- *pOriginal - structure that holds the information of all the users
- */
- void signUp(userType *pUser, userType *pOriginal){
- userType *pCurrent=NULL, *pTrail;
- string15 username;
- int unique=0;
- char cDump;
- int check, i;
- string8 authorization;
- printf("\n------SIGN UP------\n");
- do{
- printf("Enter username (3-15 characters): ");
- scanf("%s%c", username, &cDump);
- if(strlen(username)>=3 && strlen(username)<=15){
- pCurrent=pOriginal;
- unique=checkUsername(username, pOriginal);
- if(unique==1)
- {
- strcpy(pUser->username, username);
- }
- if(unique!=1)
- {
- printf("Username already exists.\n");
- }
- }
- }while(strlen(pUser->username)<3 || strlen(pUser->username)>15 || unique!=1);
- unique=0;
- do{
- printf("Enter password (6-15 characters, at least one must not be a letter): ");
- scanf("%s", pUser->password);
- for(i=0; i<strlen(pUser->password); i++){
- if(!(pUser->password[i]>='a' && pUser->password[i]<='z'|| pUser->password[i]>='a' && pUser->password[i]<='z'))
- check=1;
- }
- } while(check==0|| strlen(pUser->password)<6 || strlen(pUser->password)>15);
- getUserInfo(&pUser->info);
- do{
- printf("Account type ([S]hopper or [A]dministrator): ");
- scanf("%c%c", &pUser->type, &cDump);
- if(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'))
- printf("Invalid input.\n");
- } while(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'));
- if(pUser->type == 's' || pUser->type == 'S'){
- //shopper account is created
- pUser->creditlimit=5000.00;
- pUser->outstanding=0.00;
- pUser->nItems=0;
- printf("\nSHOPPER ACCOUNT CREATED.\n\n");
- }
- else if(pUser->type == 'a' || pUser->type == 'A'){
- //administrator account is created
- do{printf("Enter authorization code: ");
- scanf("%s", authorization);
- if(strcmp(authorization,"DLSU2017")==0)
- printf("\nADMINISTRATOR ACCOUNT CREATED.\n\n");
- else
- printf("Invalid authorization code.\n");
- }while(strcmp(authorization,"DLSU2017")!=0);
- }
- }
- /*Function logIn Allows user to log in their account after signing up by asking for their username and password.
- @param: *pUser - structure with information of current user
- accountCount - number of accounts
- *shutdown - shutdown option
- *pStock - structure with list of stocks
- *categoryCtr - number of unique categories
- */
- void logIn(userType *pUser, int accountCount, int *shutdown, ptrStock *pStock, int *categoryCtr){
- userType *pCurrent;
- char cDump;
- string15 username,
- password;
- int found=0,
- i=0,
- correct=0,
- tries=1,
- exit=0;
- printf("\n------LOG IN------\n");
- //if(pStock!=NULL)
- // viewStocks(pStock, 1);
- do{
- printf("Username: ");
- scanf("%s%c", username, &cDump);
- pCurrent=pUser;
- while(pCurrent!=NULL && i<=accountCount && found==0){
- if(strcmp(pCurrent->username, username)==0)
- found=1;
- else{
- pCurrent=pCurrent->pNext;
- i++;
- }
- }
- if(found==0)
- printf("Invalid username.\n");
- }while(found==0);
- do{
- printf("Password: ");
- scanf("%s%c", password, &cDump);
- if(strcmp(pCurrent->password, password)!=0){
- correct=0;
- tries++;
- }
- if(tries>3 || pCurrent->isLocked==1){
- pCurrent->isLocked=1;
- printf("\nYou have exceeded the amount of tries to log in.\n");
- printf("Your account is now locked.\n");
- printf("To unlock your account, please contact an administrator.\n\n");
- exit=1;
- }
- else{
- if(strcmp(pCurrent->password, password)==0)
- correct=1;
- if(correct==1)
- if(pCurrent->type=='S' || pCurrent->type=='s'){
- printf("\nGreetings shopper: %s %s %s!\n",
- pCurrent->info.name.first, pCurrent->info.name.middle, pCurrent->info.name.last);
- ////SHOPPER MENU!
- shopperMenu(pUser, pStock);
- }
- else{
- printf("\nGreetings administrator: %s %s %s!\n",
- pCurrent->info.name.first, pCurrent->info.name.middle, pCurrent->info.name.last);
- /////ADMIN MENU!!!
- adminMenu(pUser, shutdown, pStock, categoryCtr);
- }
- else
- printf("Incorrect password. You have %d attempts left.\n", 4-tries);
- }
- }while((tries>=3 || correct==0) && exit==0);
- }
- /*Function main Shows the main menu’s options to the user and allows the user to choose which option (log in or sign up).
- */
- /*
- void saveToTextFile(ptrUser pFirst){
- FILE *pText;
- string20 strName;
- if(pFirst == NULL)
- printf("Nothing to save.\n");
- else{
- printf("Enter filename: ");
- scanf("%s", strName);
- pText=fopen(strName, "wt");
- if(pText!=NULL){
- while(pFirst!=NULL){
- fprintf(pText, "%s%s\n", pFirst->username, pFirst->password);
- pFirst=pFirst->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file.\n");
- }
- }
- void saveStocksToTextFile(ptrStock pFirst){
- FILE *pText;
- string20 strName;
- if(pFirst == NULL)
- printf("Nothing to save.\n");
- else{
- printf("Enter filename: ");
- scanf("%s", strName);
- pText=fopen(strName, "wt");
- if(pText!=NULL){
- while(pFirst!=NULL){
- fprintf(pText, "%s %s %s\n%d %.2f %s\n%.2f&%.1f %d\n\n",
- pFirst->category, pFirst->prodList.prodCode, pFirst->prodList.product, pFirst->prodList.qtyAvailable,
- pFirst->prodList.purPrice, pFirst->prodList.supplier, pFirst->prodList.unitSellPrice, pFirst->prodList.discRate,
- pFirst->prodList.qtySold);
- pFirst=pFirst->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file.\n");
- }
- }
- void loadFromText(string20 strFile, ptrUser *pFirst){
- FILE *pFile;
- string20 user,
- pass;
- ptrUser pNew;
- if((pFile=fopen(strFile, "rt"))!=NULL){
- while(fscanf(pFile, "%s%s", user, pass) == 2){
- printf("%s%s\n", user, pass);
- //creation of the linked list
- pNew=malloc(sizeof(userType));
- strcpy(pNew->username, user);
- strcpy(pNew->password, pass);
- //always insert at head of list
- pNew->pNext=*pFirst;
- *pFirst=pNew;
- }
- fclose(pFile);
- }
- else
- printf("Error opening file.\n");
- }
- */
- int main(){
- int categoryCtr=0;
- ptrUser pUsers=NULL,
- pNew=NULL,
- pLast=NULL,
- pRun=NULL,
- pTrail=NULL;
- ptrStock pStocks=NULL;
- int opt=0,
- choose=0,
- accountCount=0,
- shutdown=0,
- check=0;
- char cDump;
- string20 strFile;
- do{
- printf("\n------[MAIN MENU]------\n");
- printf("1 - Log In\n");
- printf("2 - Sign Up\n");
- printf("3 - Shutdown\n\n");
- printf("Choose option: ");
- scanf("%d", &choose);
- if(choose==2){
- do{
- pNew=malloc(sizeof(userType));
- pNew->pNext=NULL;
- if(pUsers==NULL) { //list is empty
- signUp(pNew, NULL);
- pUsers=pNew;
- }
- else if(strcmp(pUsers->username, pNew->username)>0){ //connect at first node
- signUp(pNew, pUsers);
- pNew->pNext=pUsers;
- pUsers=pNew;
- }
- else{ //modifying middle of the list
- signUp(pNew, pUsers);
- pRun=pUsers;
- while(pRun != NULL && strcmp(pRun->username, pNew->username)<0){
- pTrail=pRun;
- pRun=pRun->pNext;
- }
- pTrail->pNext=pNew;
- pNew->pNext=pRun;
- }
- accountCount++;
- printf("Another user? (1 for yes, 0 for no): ");
- scanf("%d%c", &opt, &cDump);
- }while(opt==1);
- }
- if(choose==1)
- if(pUsers==NULL){
- printf("No accounts made yet.\n");
- check=1;
- }
- else
- logIn(pUsers, accountCount, &shutdown, &pStocks, &categoryCtr);
- if(choose==3)
- opt=1;
- }while((opt==0 && shutdown==0) && choose>2 || check==1);
- freeAll(&pUsers);
- freeAllStocks(&pStocks);
- /*printf("Enter filename: ");
- scanf("%s", strFile);
- saveToTextFile(pUsers);
- loadFromText(strFile, &pUsers);*/
- printf("\nShutting down Kiosk...");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement