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.
- Brent Aldwinne P. Lim, 11609281
- **********************************************************************************************************************/
- #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;
- string20 middle;
- string20 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;
- string15 password;
- userInfoType info;
- char type;
- float creditLimit;
- float outstanding;
- arrBought cart;
- int nItems;
- int locked;
- int chk;
- struct userTag *pNext;
- };
- typedef struct userTag userType;
- typedef userType *ptrUser;
- struct userProduct { //linked list for the products
- string15 category;
- string15 supplier;
- string15 product;
- string8 pCode;
- int qAvail;
- int qSold;
- float purchasePrice;
- float salePrice;
- float discountRate;
- struct userProduct *pNext;
- };
- void addNewStock(userProduct *pProd,userProduct *pNew){
- userProduct pTemp;
- pTemp=pProd;
- int choice=01
- char cDump;
- do{
- printf("Enter Category:");
- fgets(pNew->category, 16, stdin);
- printf("You entered %s Category\n",pNew->category);
- printf("Input supplier Name:");
- scanf("%s%c",pProd->supplier,&cDump);
- printf("Input product name:");
- scanf("%s%c",pNew->product,&cDump);
- printf("Enter Available Product Quantity: ");
- canf("%d%c", pNew->qAvail, &cDump);
- printf("Input Price of the Product: ");
- scanf("%f%c",pNew->purchasePrice, &cDump);
- printf("Input the Unit Selling Price of the product: ");
- scanf("%f%c", pNew->salePrice, &cDump);
- printf("Input the Discount Rate of the product: ");
- scanf("%f%c", pNew->discountRate, &cDump);
- pNew->qSold = 0;
- printf("1.Add new stock?\n")
- printf("2.Go back to menu?? \n");
- scanf("%d",&choice);
- if(n!=choice || n!=choice )
- printf("Invalid Input... Returning you to Manage Stocks Menu");
- }while(choice!=0);
- }
- }
- void viewAllStocks(){
- }
- void viewCategory(){
- }
- void viewToReorder(){
- }
- void modifyStockInfo(){
- }
- void restock(){
- }
- void saveInventory(){
- }
- //Function Name: manageStocks
- //Function Required Input Parameters: option
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To have access on the stocks of the progam
- void manageStocks(userProduct *pProd,userProduct *pNew){
- int choice;
- int end=0;
- printf(" MANAGE STOCKS MENU \n");
- printf("1.Add New Stock");
- printf("2.View All Stocks");
- printf("3.View Stocks by Category");
- printf("4.View Stocks to Reorder");
- printf("5.Modify Stock Info");
- printf("6.Restock");
- printf("7.Save Inventory");
- printf("8.Back to Admin Menu");
- do{
- switch(choice){
- case 1:addNewStock(pProd,pNew);
- break;
- case 2:viewAllStocks();
- break;
- case 3:viewCategory();
- break;
- case 4:viewToReorder();
- break;
- case 5:modifyStockInfo();
- break;
- case 6:restock();
- break;
- case 7:saveInventory();
- break;
- case 8:end=0;
- }
- }while(end!=0);
- }
- //Function Name: manageAccounts
- //Function Required Input Parameters: choice
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To allow user to manage accounts of the kiosk
- void manageAccounts(ptrUser pUser){
- int choice,end=1;
- ptrUser *pTemp=NULL;
- do
- {
- printf(" MANAGE ACCOUNTS MENU \n");
- printf("Enter choice:");
- 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");
- printf("Enter choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: viewLocked(pUser);
- break;
- case 2: unlockAccount(pUser);
- break;
- case 3: unlockAll(pUser);
- break;
- case 4: viewBal(pUser);
- break;
- case 5: end=0;
- }
- } while (end);
- }
- //Function Name: viewLocked
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To view accounts that are locked
- void viewLocked (ptrUser *pUser){
- ptrUser *pTemp=NULL;
- pTemp=pUser;
- printf("View Locked Accounts:\n");
- do
- {
- if ((*pTemp).locked==1)
- printf("Account: %s\n", ctr, pTemp->username);
- pTemp=pTemp->pNext;
- } while (pTemp!=NULL);
- }
- //Function Name: unlockAccount
- //Function Required Input Parameters: username of desired account
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To unlock account
- void unlockAccount (ptrUser *pUser){
- string15 user;
- ptrUser *pTemp=NULL;
- int comp=1, choice, end=0;
- pTemp=pUser;
- printf("Unlock account: \n");
- do
- {
- printf("Enter username of the account you want to unlock: \n");
- scanf("%s",&user);
- comp=strcmp(user, (*pTemp).username);
- do
- {
- if ((*pTemp).locked==1 && compare==0)
- {
- (*pTemp).locked=0;
- pTemp=(*pTemp).pNext;
- }
- } while (pTemp!=NULL);
- printf("%s has been unlocked.\n",(*pTemp).username);
- printf("Unlock another user? \n");
- printf("1. Yes\n");
- printf("2. No\n");
- scanf("%d",&choice);
- do
- {
- switch (choice)
- {
- case 1: end=0;
- break;
- case 2: end=1;
- default:printf("Invalid Input! Try Again!");
- }
- } while (choice!=1 && choice!=2);
- } while (end==0);
- }
- //Function Name: unlockAll
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: unlocks all locked accounts
- void unlockAll (ptrUser *pUser){
- ptrUser *pTemp=NULL;
- pTemp=pUser;
- do
- {
- if ((*pTemp).locked==1)
- (*pTemp).locked=0;
- pTemp=(pTemp).pNext;
- } while (pTemp!=NULL);
- printf("All accounts are unlocked!\n");
- }
- //Function Name: viewBal
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To view accounts that have outstanding balance
- void viewBal (ptrUser *pUser){
- ptrUser *pTemp=NULL;
- printf("View Outstanding Balance: \n");
- do
- {
- if ((*pTemp).outstanding <= 0.00)
- printf("Sorry, outstanding balance is 0.00\n");
- else if (temp->outstanding > 0.00)
- {
- printf("Username: %s",(*pTemp).username);
- printf("Outstanding Balance is: %f\n", (*pTemp).outstanding);
- }
- pTemp=(*pTemp).next;
- } while (pTemp!=NULL);
- }
- //Function Name: modifyInfo
- //Function Required Input Parameters: option
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: allow user to choose on what to modify
- void modifyInfo(ptrUser pUser){
- int choice;
- printf(" MODIFY INFO MENU \n ");
- printf("Enter option\n");
- printf("1.Change Name\n");
- printf("2.Change address \n");
- printf("3.Change password \n");
- printf("4.Back to Shopper Menu");
- scanf("%d",choice);
- switch(choice){
- case 1: editName(&(*pUser).info);
- case 2: editAddress(&(*pUser).info);
- case 3: editPassword(pUser);
- }
- }
- //Function Name: editPassword
- //Function Required Input Parameters: password
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To edit password
- void editName(userInfoType *pInfo){
- printf("Enter the following to change 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);
- (*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';
- printf("Edit successful!");
- printf("Name: %s, %s %s\n",(*pInfo).name.last, pInfo -> name.first, pInfo -> name.middle);
- system("cls");
- }
- //Function Name: editAddress
- //Function Required Input Parameters: address
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To edit address
- void editAddress(userInfoType *pInfo){
- printf("Enter to change the address address\n");
- fgets((*pInfo).address,51,stdin);
- (*pInfo).address[strlen((*pInfo).address)-1] = '\0';
- printf("Adress: %s\n",(*pInfo).address);
- system("cls");
- }
- //Function Name: editPassword
- //Function Required Input Parameters: password
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To edit password
- void editPassword(ptrUser *pUsers){
- char cDump;
- do{
- printf("Enter New Password: ");
- scanf("%s%c",(*pUsers).password,&cDump);
- } while (strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15 || checkPword(pUsers)==0);
- printf("Password successfully changed!");
- printf("Your new password is: %s \n",(*pUsers).password);
- printf("%s\n", (*pUsers).password);
- system("cls");
- }
- //Function Name: displayAdmin
- //Function Required Input Parameters: option on what admin wants to do
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: allow admin to do what the user desires with account
- void displayAdmin(ptrUser pUsers){
- system("cls");
- userProduct pProd=NULL;
- userProduct pNew;
- int choice,end=0;
- printf(" ADMINISTRATOR MENU \n ");
- printf("Enter number of choice:\n");
- printf("1.Manage Accounts\n");
- printf("2.Manage Stocks\n");
- printf("3.Prepare Delivery Report\n");
- printf("4.Shutdown Kiosk\n");
- printf("5.Log out \n");
- scanf("%d",&choice);
- do{
- switch(choice){
- case 1:system("cls");
- manageAccounts(pUsers);
- break;
- case 2: system("cls");
- manageStocks(pProd,pNew);
- break;
- case 3:system("cls");
- printf("Preparing Delivery Report...");
- deliveryReport(pUser,pProd);
- break;
- case 4: printf("Thank you! Shop with us again!");
- exit(0);
- break;
- case 5:printf("You have logged out");
- end=0;
- }
- }while(end);
- }
- //Function Name: displayShopper
- //Function Required Input Parameters: option on what the shopper wants to do
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: allows user to
- void displayShopper(ptrUser pUsers){
- system("cls");
- int choice,end=0;
- printf(" SHOPPER MENU \n ");
- printf("Enter number of choice:\n");
- printf("1.Modify User Info\n");
- printf("2.Browse All Products \n");
- printf("3.Browse All Products by Category\n");
- printf("4.Browse Products on Sale");
- printf("5.Add Item to Cart \n");
- printf("6.View Items in Cart");
- scanf("%d",&choice);
- do{
- switch(choice){
- case 1: modifyInfo(pUsers);
- break;
- case 2: ;
- break;
- case 3: browse
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- }
- }while(end);
- }
- //Function Name: numUsers
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: returns number of users
- //Function Description and or Algorithim: To count number of accounts in the system
- int numUsers(ptrUser pUsers){
- int ctr=0;
- while(pUsers != NULL){
- ctr++;
- pUsers = pUsers->pNext;
- }
- return ctr;
- }
- //Function Name: logIn
- //Function Required Input Parameters: username and password. if admin,authorization code is also needed.
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: to allow users access for their account
- void logIn(ptrUser pUsers){
- string15 user,pword;
- string8 accesscode;
- system("cls");
- int approve=0;
- int attempts=0;
- int end=1;
- if((*pUsers).type == 's' || (*pUsers).type == 'S')
- do {
- printf("Enter Username: ");
- scanf("%s",&user);
- if (strcmp((*pUsers).username,user) == 0 && attempts < 3){
- do{
- printf("Enter Password: ");
- scanf("%s",&pword);
- if (strcmp (pUsers->password,pword)!=0){
- printf("Try again, %d try/s left\n",3-attempts);
- attempts++;
- }
- else if (strcmp((*pUsers).password,pword) == 0)
- approve=1;
- }while (attempts <= 3 && strcmp (pUsers->password,pword) !=0);
- }
- /*if (strcmp(pUsers->password,input)==0)
- if (user.type == 's')
- shopper(&(*pUsers));
- else if (user.type == 'A')
- administrator(&(*pUsers))
- else if (attempts >= 3)*/
- } while (strcmp (pUsers->username,user));
- if (approve==1)
- displayShopper(pUsers);
- else if((*pUsers).type == 'a' || (*pUsers).type == 'A')
- do{
- printf("Enter Username: ");
- scanf("%s",&user);
- if (strcmp((*pUsers).username,user) == 0 && attempts < 3){
- do{
- printf("Enter Password: ");
- scanf("%s",&pword);
- do{
- printf("Enter access code:");
- scanf("%s",&accesscode);
- if (strcmp (accesscode,"DLSU2017")!=0){
- printf("Try again, %d try/s remaining\n",3-attempts);
- attempts++;
- }
- else approve=1,end=0;
- } while(attempts <= 3 && strcmp(accesscode,"DLSU2017") != 0);
- if (strcmp (pUsers->password,pword)!=0){
- printf("Try again, %d try/s remaining\n",3-attempts);
- attempts++;
- }
- else if (attempts>3)
- printf("Account Locked! Back to Menu!");
- (*pUsers).locked=1;
- getch();
- end = 0;
- } while (attempts <= 3 && strcmp (pUsers->password,pword) !=0);
- }
- else if(attempts>3)
- printf("Exceeded number of attempts. Locking account. Press any keys.");
- else
- printf("Try again, %d try/s remaining\n",3-attempts);
- attempts++;
- }while (strcmp ((*pUsers).username,user) && end==1);
- if(approve==1)
- displayAdmin(pUsers);
- }
- ptrUser search(ptrUser pFirst, string15 username){
- ptrUser pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(username, pRun->username) != 0){
- pRun = pRun->pNext;
- }
- return pRun;
- }
- //Function Name: deleteNode
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To delete node
- void deleteNode(ptrUser *pFirst,string15 username){
- ptrUser pFind, pRun;
- if (pFirst == NULL)
- printf("List is empty");
- else{
- pFind = search(*pFirst, username);
- if (pFind == NULL)
- printf("%s is not in the list\n",username);
- else //found note to delete
- if (pFind == *pFirst){
- *pFirst = (*pFirst)->pNext;
- free(pFind);
- pFind = NULL;
- }
- else { //delete from middle or end
- pRun = *pFirst;
- while (pRun->pNext != pFind){
- pRun = pRun->pNext;
- }
- pRun->pNext = pFind->pNext;
- free(pFind);
- pFind = NULL;
- }
- }
- }
- //Function Name: displayAllRecur & displayAll
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To display all accounts
- void displayAllRecur(ptrUser pUsers){
- if(pUsers != NULL){
- printf("%s\n",pUsers->username);
- displayAllRecur(pUsers->pNext);
- }
- }
- //Function Name: freeAll
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To free allocated memory of program
- void freeAll(ptrUser * pFirst){
- ptrUser pDel;
- while(*pFirst != NULL){
- pDel = *pFirst;
- *pFirst = (*pFirst)->pNext;
- free(pDel);
- }
- }
- void displayAll(ptrUser pUsers){
- while(pUsers != NULL){
- printf("%s\n",pUsers->username);;
- pUsers = pUsers->pNext;
- }
- }
- //Function Name: getUserInfo
- //Function Required Input Parameters: complete name and address
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: to provide information for the account of user
- void getUserInfo(userInfoType *pInfo){
- printf("Enter 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\n");
- fgets((*pInfo).address,51,stdin);
- (*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';
- printf("Name: %s, %s %s\n",(*pInfo).name.last, pInfo -> name.first, pInfo -> name.middle);
- printf("Adress: %s\n",pInfo->address);
- }
- //Function Name: checkPassword
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: returns 0 and 1 for the status of approval
- //Function Description and or Algorithim: To check if password is approved
- int checkPassword(userType *pUser){
- int i=0;
- int ctr=0;
- while(i<strlen((*pUser).password)){
- if ((*pUser).password[i] < 'A' || (*pUser).password[i] > 'Z')
- if ((*pUser).password[i] < 'a' || (*pUser).password[i] > 'z')
- ctr++;
- i++;
- }
- if (ctr>0)
- return 0;
- else return 1;
- }
- //Function Name: checkUser
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: returns 0 or 1 to check if username is taken
- //Function Description and or Algorithim: To know if username is used
- int checkUser(string15 username, string15 user){
- if (strcmp(username,user)==0)
- return 1;
- else return 0;
- }
- //Function Name: SignUp
- //Function Required Input Parameters: username and password. if admin,authorization code is also needed.
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To create account for user
- void signUp(userType *pUser,userType *pUsers){
- system("cls");
- char cDump;
- string8 access;
- int check=0;
- string15 temp;
- do{
- printf("Enter username:");
- scanf("%s",(*pUser).username); //(*pUser).username can be (pUser -> username)
- //scanf("%s%c", (*pUser).username,&cDump);
- if(strlen((*pUser).username) < 3 || strlen((*pUser).username) > 15)
- printf("Invalid username! Try again!\n");
- else strcpy((*pUser).username,temp);
- (*pUser).chk = checkUser((*pUser).username,temp);
- while(pUsers!=NULL){
- if((*pUser).chk==0)
- do{
- printf("Username already taken! Try again!\n");
- printf("Enter username:");
- scanf("%s",(*pUser).username);
- (*pUser).chk=checkUser((*pUser).username,temp);
- }while((*pUser).chk == 0);
- }
- else printf("Username approved!");
- (*pUser).chk == 1;
- } while (strlen((*pUser).username) < 3 || strlen((*pUser).username) > 15 );
- printf("%s\n",(*pUser).username);
- do{
- printf("Enter password:");
- //scanf("%s",(*pUser).password); //(*pUser).password can be (pUser -> password)
- scanf("%s%c", (*pUser).password,&cDump);
- if(strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15)
- do{
- printf("Invalid! Try Again!");
- printf("Enter password:");
- scanf("%s%c", (*pUser).password,&cDump);
- }while(strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15);
- else printf("Password is approved!");
- } while (strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15);
- printf("%s \n",(*pUser).password);
- getUserInfo(&(*pUser).info);
- //getUserInfo(pUser -> info);
- printf("Account Type:\n");
- printf("a or A - Administrator \n");
- printf("s or S - Shopper \n");
- scanf("%c%c",&(*pUser).type,&cDump);
- if((*pUser).type == 's' || (*pUser).type =='S'){
- printf("Account Activation successful!\n");
- (*pUser).creditLimit = 5000.00;
- (*pUser).outstanding = 0.00;
- (*pUser).nItems = 0;
- }
- else if((*pUser).type == 'a'|| (*pUser).type =='A'){
- while(strcmp(access,"DLSU2017") != 0){
- printf("Admin Code:");
- scanf("%s%c",&access,&cDump);
- if(strcmp(access,"DLSU2017")==0)
- check=1;
- if(check=1)
- (*pUser).type = 'A';
- printf("Account Authentication successful!\n");
- }
- }
- else printf("Invalid account type. Try Again");
- }
- int main(){
- /*
- userType user;
- userType *pUsers = NULL;
- userType *pNew;
- */
- ptrUser pUsers = NULL;
- ptrUser pNew,/*pLast*/pRun,pTrail;
- string15 username;
- int opt;
- int end = 1;
- char cDump;
- //Function Name: main
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Displays the options for user to choose
- do{
- printf("Enter your number of option:\n\n");
- printf("1:Log In \n");
- printf("2:Sign Up \n");
- printf("3.Delete account\n");
- printf("4.Display all active accounts\n");
- printf("5.Close program \n");
- printf("Choice:");
- scanf("%d%c",&opt,&cDump);
- switch(opt){
- case 1:logIn(pNew);
- case 2:pNew = malloc(sizeof(userType));
- signUp(pNew,pUsers);
- pNew -> pNext = NULL;
- if (pUsers == NULL) //first user
- pUsers = pNew; //pNew is first
- else if (strcmp (pUsers->username, pNew->username)>0){ //connect as first node
- pNew->pNext = pUsers;
- pUsers = pNew;
- }
- else { //modifying middle of the list
- pRun = pUsers ;
- while (pRun != NULL && strcmp(pRun->username, pNew->username) < 0) {
- pTrail = pRun;
- pRun = pRun->pNext;
- }
- pTrail->pNext = pNew;
- pNew->pNext=pRun;
- }
- break;
- case 3:printf ("What account do you want to delete?");
- scanf ("%s", username);
- deleteNode(&pUsers, username);
- break;
- case 4:displayAllRecur(pUsers);
- displayAll(pUsers);
- break;
- case 5:freeAll(&pUsers);
- end=0;
- }
- }while(end);
- return 0;
- }
- /* do{
- pNew=malloc(sizeof(userType));
- signUp(pNew);
- (*pNew).pNext = NULL; //pNew->pNext = NULL
- if (pUsers == NULL) //if initially empty
- pUsers = pNew; //pNew is the first node
- else //connect nodes to the list
- pLast->pNext = pNew;
- pLast = pNew;
- printf("Another user?");
- scanf("%d%c",&opt,&cDump);
- }while(opt == 1);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement