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>
- #include <time.h>
- #define MAX_CART 100
- typedef char string15[16];
- typedef char string20[21];
- typedef char string50[51];
- typedef char string8[9];
- typedef struct{ //username structure
- string20 first;
- string20 middle;
- string20 last;
- }nameType;
- typedef struct{ //user info structure
- nameType name;
- string50 address;
- }userInfoType;
- typedef struct{
- string8 code;
- int qty;
- }prodBoughtType;
- typedef struct{
- string8 prodcode;
- string15 supplier;
- string15 product;
- int quantAvail;
- int quantSold;
- float purchPrice;
- float unitsellPrice;
- float discount;
- }productType; //products structure
- typedef struct productType prodType;
- typedef prodType *ptrProd;
- struct stocksTag{ //structure for stocks
- string15 category;
- productType stockInfo;
- struct stockTag *pNext;
- };
- typedef struct stocksTag stocksType;
- typedef stocksType * ptrStocks;
- typedef prodBoughtType arrBought[MAX_CART];
- struct userTag{ //user structure
- string15 username;
- string15 password;
- userInfoType info;
- char type;
- float creditLimit;
- float outstanding;
- arrBought cart;
- int nItems;
- int locked;
- int loggedin;
- struct userTag *pNext;
- };
- typedef struct userTag userType;
- typedef userType * ptrUser;
- //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);
- }
- }
- //Function Name: displayAll
- //Function Required Input Parameters: linked list of users
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To display all active users
- void displayAll(ptrUser pUsers){
- while(pUsers != NULL){
- printf("%s\n",pUsers->username);;
- pUsers = pUsers->pNext;
- }
- }
- int checkPass (userType *pUser)
- {
- int i, valid=0;
- for(i=0;i<(strlen(pUser->password));i++){
- if (pUser->password[i] < 'a' || pUser->password[i] >'z')
- if (pUser->password[i] < 'A' || pUser->password[i] >'Z')
- valid=1;
- }
- return valid;
- }
- //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: search
- //Function Required Input Parameters: first node of linked list and input username
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: to search for user in the linked list
- 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: uniqueUser
- //Function Required Input Parameters: linked list structure of users and string of new username
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: to check if username is already taken
- int uniqueUser(userType *pUsers, string15 username){
- ptrUser pRun;
- pRun = pUsers;
- while (pRun != NULL && strcmp(username, pRun->username)!=0)
- pRun = pRun->pNext;
- if (pRun == NULL)
- return 1;
- else
- return 0;
- }
- //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 (userType *pUser){
- userType *pTemp=NULL;
- pTemp=pUser;
- printf("View Locked Accounts:\n");
- do
- {
- if ((*pTemp).locked==1)
- printf("Account: %s\n", 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 (userType *pUser){
- string15 user;
- userType *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 && comp==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 (userType *pUser){
- userType *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 (userType *pUser){
- userType *pTemp=NULL;
- printf("View Outstanding Balance: \n");
- do
- {
- if ((*pTemp).outstanding <= 0.00)
- printf("Sorry, outstanding balance is 0.00\n");
- else if (pTemp->outstanding > 0.00)
- {
- printf("Username: %s",(*pTemp).username);
- printf("Outstanding Balance is: %f\n", (*pTemp).outstanding);
- }
- pTemp=(*pTemp).pNext;
- } while (pTemp!=NULL);
- }
- //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(userType *pUsers){
- char cDump;
- do{
- printf("Enter New Password: ");
- scanf("%s%c",(*pUsers).password,&cDump);
- } while (strlen((*pUsers).password) < 6 || strlen((*pUsers).password) > 15 || checkPass(pUsers)==0);
- printf("Password successfully changed!");
- printf("Your new password is: %s \n",(*pUsers).password);
- printf("%s\n", (*pUsers).password);
- system("cls");
- }
- //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(userType *pUser, userInfoType *pInfo){
- 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(pInfo);
- break;
- case 2: editAddress(pInfo);
- break;
- case 3: editPassword(pUser);
- break;
- }
- }
- //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(userType* pUser){
- int choice,end=1;
- 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: addNewStock
- //Function Required Input Parameters: input the stock wanted to add in the linked list
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Allows user to
- void addNewStock(stocksType *pStocks,stocksType *pNewS){
- stocksType pTemp;
- pTemp=pProd;
- int choice=01
- char cDump;
- do{
- printf("Enter Category:");
- fgets(pNewS->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(){
- char exit = '\0';
- }
- //Function Name: manageStocks
- //Function Required Input Parameters: enter the linked list of stocks
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: allow admin to do what the user desires with the stocks
- */
- /*void manageStocks(userType *pUsers, stocksType *pStock, stocksType *pNewS, stocksType *pLastS){
- int choice, exit, page = 0;
- char cDump, exit2 = '\0';
- ptrStocks pRun;
- string8 prodcode;
- string15 saveloc, category;
- pStock = NULL;
- pNewS = NULL;
- pLastS = NULL;
- do {
- printf(" 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.Update Inventory from File \n");
- printf("8.Return to Administrator Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do{
- pNewS = malloc(sizeof(stocksType));
- addNewStock(pStock, pNewS);
- pNewS->pNext = NULL;
- if (pStock == NULL) //if initially empty
- pStock = pNewS; //pNew is the first node
- else //connect nodes to the list
- pLastS->pNext = pNewS;
- pLastS = pNewS;
- }while(exit==0);
- break;
- case 2:
- do {
- printf("View All Stocks \n");
- pRun = pStock;
- printf("Category Supplier Product Qty Available Purchase Price Selling Price Qty Sold Product Code \n");
- while (pRun != NULL && page < 20){
- printf("%s %s %s %d %f %f %d %s \n",
- pRun->category, (*pRun).stockInfo.supplier, (*pRun).stockInfo.product, (*pRun).stockInfo.quantAvail, (*pRun).stockInfo.purchPrice, (*pRun).stockInfo.unitsellPrice, (*pRun).stockInfo.quantSold, (*pRun).stockInfo.prodcode);
- pRun = pRun->pNext;
- page++;
- }
- page = 0;
- }while (exit2=='\0');
- break;
- case 3: do {
- printf("Input the category");
- printf("Input: ");
- scanf("%s%c",category, &cDump);
- searchStock (pStock, category);
- if (searchStock (pStock, category)==NULL)
- printf("Category not found \n");
- else if (searchStock (pStock, category)!=NULL)
- printf("Viewing Stocks by Category \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- if (strcmp(pStock->category,category)==0){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).stockInfo.supplier, (*pRun).stockInfo.product, (*pRun).stockInfo.quantAvail, (*pRun).stockInfo.purchPrice, (*pRun).stockInfo.unitsellPrice, (*pRun).stockInfo.quantSold, (*pRun).stockInfo.prodcode);
- pRun = pRun->pNext;
- }
- }
- printf("Press 0 to exit");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 4: do {
- printf("Viewing Stocks to Reorder \n");
- pRun = pStock;
- do{
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).stockInfo.supplier, (*pRun).stockInfo.product, (*pRun).stockInfo.quantAvail, (*pRun).stockInfo.purchPrice, (*pRun).stockInfo.unitsellPrice, (*pRun).stockInfo.quantSold, (*pRun).stockInfo.prodcode);
- pRun = pRun->pNext;
- page++;
- }while (pRun != NULL && (*pRun).stockInfo.quantAvail == 0 && page < 20);
- page = 0;
- printf("Press N return to exit or press ENTER to next page. \n");
- scanf("%c%c", &exit2, &cDump);
- }while (exit2=='\0');
- break;
- case 5: do {
- printf("Viewing All Stocks \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).stockInfo.supplier, (*pRun).stockInfo.product, (*pRun).stockInfo.quantAvail, (*pRun).stockInfo.purchPrice, (*pRun).stockInfo.unitsellPrice, (*pRun).stockInfo.quantSold, (*pRun).stockInfo.prodcode);
- pRun = pRun->pNext;
- }
- printf("Modify Stock Info \n");
- modifyStockInfo(pStock);
- printf("Press 0 to exit");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 6: do {
- printf("Restock \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).stockInfo.supplier, (*pRun).stockInfo.product, (*pRun).stockInfo.quantAvail, (*pRun).stockInfo.purchPrice, (*pRun).stockInfo.unitsellPrice, (*pRun).stockInfo.quantSold, (*pRun).stockInfo.prodcode);
- pRun = pRun->pNext;
- }
- printf("Input the product code of the product that will be restocked: ");
- scanf("%s%c",prodcode, &cDump);
- pRun = pStock;
- while (pRun != NULL && strcmp(prodcode, (*pRun).stockInfo.prodcode)!=0){
- pRun = pRun->pNext;
- if (pRun == NULL){
- printf("Last input product code not found. Not restocked. Returning to Manage Stocks Menu \n");
- exit = 0;
- }
- if (pRun != NULL && strcmp(prodcode, (*pRun).stockInfo.prodcode)==0){
- printf("Additional Quantity for this item: ");
- scanf("%d%c", (*pRun).stockInfo.quantAvail, &cDump);
- printf("This product has been restocked and has %d quantity available. \n", (*pRun).stockInfo.quantAvail);
- }
- }
- printf("Press 0 to exit");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 7:
- break;
- default: choice = 0;
- break;
- }
- }while(choice > 0 && choice < 9 );
- }*/
- //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(userType *pUsers, userType *pNew, userType *pLast, stocksType *pStock, stocksType *pNewS, stocksType *pLastS){
- system("cls");
- userInfoType *pInfo;
- 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(pUsers, pStock, pNewS, pLastS);
- break;*/
- case 3:/*system("cls");
- printf("Preparing Delivery Report...");
- deliveryReport(pUsers, pStock, pNewS, &pUsers->info);
- break;*/
- case 4: printf("Shutting down Kiosk! \n Thank you! Shop with us again!");
- end=0;
- free(pUsers);
- break;
- case 5:(*pUsers).loggedin=0;
- 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(userType *pUsers, userType *pNew, userType *pLast, stocksType *pStock, stocksType *pNewS, stocksType *pLastS){
- 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:printf("Browsing All products");
- break;
- case 3:;
- break;
- case 4:
- break;
- case 5:
- break;
- }
- }while(end);
- }
- //Function Name: logIn
- //Function Required Input Parameters: input linkedlist of users and stocks
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: allows user to login to account
- void logIn(userType *pUsers, userType *pNew, userType *pLast, stocksType *pStock, stocksType *pNewS, stocksType *pLastS){
- string15 user,pword;
- string8 accesscode;
- userType *userPointer;
- userType *pwordPointer;
- char cDump;
- int attempts=0;
- int approve=0;
- int end=1;
- do {
- printf("Enter Username: ");
- scanf("%s%c",user,&cDump);
- printf("Enter Password:");
- scanf("%s%c",pword,&cDump);
- if(pUsers!=NULL){
- userPointer=search(pUsers,user);
- pwordPointer=search(pUsers,pUsers->username);
- }
- if(pUsers->locked==1){
- printf("Account locked! Account inaccessible at the moment!");
- }
- if (strcmp((*pUsers).username,user) == 0 && attempts < 3){
- do{
- if (strcmp (pUsers->password,pword)!=0){
- printf("Try again, %d try/s left\n",3-attempts);
- attempts++;
- printf("Enter Password:");
- scanf("%s%c",pword,&cDump);
- }
- else if (strcmp((*pUsers).password,pword) == 0)
- approve=1;
- }while (attempts <= 3 && strcmp (pUsers->password,pword) !=0 && approve==0);
- if(attempts>3){
- (*pUsers).locked=1;
- printf("Account has been locked! return to main menu \n");
- end=0;
- }
- }
- else{
- printf("Incorrect username! Try again!");
- printf("Enter Username: ");
- scanf("%s%c",user,&cDump);
- printf("Enter Password:");
- scanf("%s%c",pword,&cDump);
- }
- }while (strcmp (pUsers->username,user) && end==1);
- if((*pUsers).type == 'A' && (*pUsers).locked==0){
- do{
- printf("Enter access code:");
- scanf("%s",accesscode);
- if (strcmp (accesscode,"DLSU2017")!=0){
- printf("Try again!");
- }
- else (*pUsers).loggedin=1,end=0;
- displayAdmin(pUsers,pNew,pLast, pStock, pNewS, pLastS);
- }while(attempts <= 3 && strcmp(accesscode,"DLSU2017") != 0);
- }
- else if((*pUsers).type=='S' && (*pUsers).locked==0){
- (*pUsers).loggedin=1;
- displayShopper(pUsers,pNew,pLast, pStock, pNewS, pLastS);
- }
- }
- //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;
- char userTypeInput;
- string15 tempuser;
- string8 access;
- int check=0;
- do{
- printf("Enter username:");
- scanf("%s%c",(*pUser).username,&cDump); //(*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 check=uniqueUser(pUsers,(*pUser).username);
- if(check==0){
- do{
- printf("Username already taken! Try again!\n");
- printf("Enter username:");
- scanf("%s%c",(*pUser).username,&cDump);
- uniqueUser(pUser,tempuser);
- }while(check == 0);
- }
- else printf("Username approved!");
- } while (strlen((*pUser).username) < 3 || strlen((*pUser).username) > 15 || check!=1);
- 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! Password either too long or too short. Try Again!");
- printf("Enter password:");
- scanf("%s%c", (*pUser).password,&cDump);
- }while(strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15);
- check=checkPass(pUser);
- if(check==0){
- do{
- printf("Password should at least contain 1 non-letter character! Try Again!");
- printf("Enter password:");
- scanf("%s%c", (*pUser).password,&cDump);
- }while(check==0);
- }
- else printf("Password is approved!");
- } while (strlen((*pUser).password) < 6 || strlen((*pUser).password) > 15 || check==0);
- 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");
- printf("Enter Account Type:");
- scanf("%c%c",&userTypeInput,&cDump);
- if(userTypeInput == 's' || userTypeInput == 'S'){
- (*pUser).type = 'S';
- (*pUser).creditLimit = 5000.00;
- (*pUser).outstanding = 0.00;
- (*pUser).nItems = 0;
- printf("Account Activation successful!\n");
- }
- else if(userTypeInput == 'a' || userTypeInput =='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 \n");
- while (userTypeInput != 's' && userTypeInput != 'S' && userTypeInput != 'a' && userTypeInput != 'A'){
- printf("Input: ");
- scanf("%c%c",&userTypeInput, &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
- int main(){
- ptrUser pUsers = NULL;
- ptrUser pNew = NULL;
- ptrUser pLast= NULL,pRun,pTrail;
- ptrStocks pStock,pNewS,pLastS;
- string15 username;
- int opt;
- int end = 1;
- char cDump;
- 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(pUsers, pNew, pLast, pStock, pNewS, pLastS);
- 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:displayAll(pUsers);
- break;
- case 5:freeAll(&pUsers);
- end=0;
- }
- }while(end);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement