Advertisement
TH_Pallab

Admin Without File

Mar 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int cnt, choice;
  9.  
  10. struct item
  11. {
  12.     char name[100];
  13.     int price;
  14.     int quantity;
  15.     struct item *nextsnacks;
  16.     struct item *nextmeals;
  17.     struct item *nextdrinks;
  18. }*snacksvariable, *mealsvariable, *drinksvariable, *snackstemp, *mealstemp, *drinkstemp;
  19.  
  20. struct head
  21. {
  22.     int counter;
  23.     struct item *pointer;
  24. }*sheadvariable, *mheadvariable, *dheadvariable;
  25.  
  26. void creat()
  27. {
  28.     int take;
  29.     printf("\nCategories:\n");
  30.     printf("\t1 = Snacks\n");
  31.     printf("\t2 = Meal\n");
  32.     printf("\t3 = Drinks\n");
  33.     printf("\n\tSelect a Category: ");
  34.     scanf("%d",&take);
  35.  
  36.     if (take == 1)
  37.     {
  38.         snacksvariable = (struct item*) malloc(sizeof (struct item));
  39.         printf("\n\tPlease Enter The Name of This Item: ");
  40.         cin.ignore();
  41.         gets(snacksvariable -> name);
  42.         printf("\n\tPlease Enter The Price: ");
  43.         scanf("%d",&snacksvariable -> price);
  44.         snacksvariable -> quantity = 10;
  45.         snacksvariable -> nextsnacks = NULL;
  46.         sheadvariable -> counter++;
  47.  
  48.         if (sheadvariable -> counter != 1)
  49.             snacksvariable -> nextsnacks = sheadvariable -> pointer;
  50.         sheadvariable -> pointer = snacksvariable;
  51.         printf("\n\t== Successfully Added a New Snacks Item ==\n");
  52.     }
  53.  
  54.     else if (take == 2)
  55.     {
  56.         mealsvariable = (struct item*) malloc(sizeof (struct item));
  57.         printf("\n\tPlease Enter The Name of This Item: ");
  58.         cin.ignore();
  59.         gets(mealsvariable -> name);
  60.         printf("\n\tPlease Enter The Price: ");
  61.         scanf("%d",&mealsvariable -> price);
  62.         mealsvariable -> quantity = 10;
  63.         mealsvariable -> nextmeals = NULL;
  64.         mheadvariable -> counter++;
  65.  
  66.         if (mheadvariable -> counter != 1)
  67.             mealsvariable -> nextmeals = mheadvariable -> pointer;
  68.         mheadvariable -> pointer = mealsvariable;
  69.         printf("\n\t== Successfully Added a New Snacks Item ==\n");
  70.     }
  71.  
  72.     else if (take == 3)
  73.     {
  74.         drinksvariable = (struct item*) malloc(sizeof (struct item));
  75.         printf("\n\tPlease Enter The Name of This Item: ");
  76.         cin.ignore();
  77.         gets(drinksvariable -> name);
  78.         printf("\n\tPlease Enter The Price: ");
  79.         scanf("%d",&drinksvariable -> price);
  80.         drinksvariable -> quantity = 10;
  81.         drinksvariable -> nextdrinks = NULL;
  82.         dheadvariable -> counter++;
  83.  
  84.         if (dheadvariable -> counter != 1)
  85.             drinksvariable -> nextdrinks = dheadvariable -> pointer;
  86.         dheadvariable -> pointer = drinksvariable;
  87.         printf("\n\t== Successfully Added a New Snacks Item ==\n");
  88.     }
  89.  
  90.     else
  91.         creat();
  92. }
  93.  
  94. void display()
  95. {
  96.     snacksvariable = (struct item*) malloc(sizeof (struct item));
  97.     printf("\nCategories:\n");
  98.     printf("\t1 = Snacks\n");
  99.     printf("\t2 = Meal\n");
  100.     printf("\t3 = Drinks\n");
  101.     printf("\n\tSelect a Category: ");
  102.     scanf("%d",&choice);
  103.     printf("\t-----------------------------------------------------------\n");
  104.     printf("\n\t No.\tName\t\t\tPrice\t\tQuantity\n");
  105.     printf("\t-----------------------------------------------------------\n");
  106.     int number = 0;
  107.     if (choice == 1)
  108.     {
  109.         snackstemp = sheadvariable -> pointer;
  110.         while (snackstemp != NULL)
  111.         {
  112.             number++;
  113.             printf("\t %d.",number);
  114.             cout << "\t" << snackstemp -> name;
  115.             printf("\t\t %d\t\t   %d\n",snackstemp -> price, snackstemp -> quantity);
  116.             snackstemp = snackstemp -> nextsnacks;
  117.         }
  118.     }
  119.  
  120.     else if (choice == 2)
  121.     {
  122.         mealstemp = mheadvariable -> pointer;
  123.         while (mealstemp != NULL)
  124.         {
  125.             number++;
  126.             printf("\t %d.",number);
  127.             cout << "\t" << mealstemp -> name;
  128.             printf("\t\t %d\t\t   %d\n",mealstemp -> price, mealstemp -> quantity);
  129.             mealstemp = mealstemp -> nextmeals;
  130.         }
  131.     }
  132.  
  133.     else if (choice == 3)
  134.     {
  135.         drinkstemp = dheadvariable -> pointer;
  136.         while (drinkstemp != NULL)
  137.         {
  138.             number++;
  139.             printf("\t %d.",number);
  140.             cout << "\t" << drinkstemp -> name;
  141.             printf("\t\t %d\t\t   %d\n",drinkstemp -> price, drinkstemp -> quantity);
  142.             drinkstemp = drinkstemp -> nextdrinks;
  143.         }
  144.     }
  145. }
  146.  
  147. traverse (struct item *temp, int take, int option, int catagory)
  148. {
  149.     if (catagory == 1)
  150.     {
  151.         if (temp != NULL)
  152.         {
  153.             cnt++;
  154.             if (cnt == take)
  155.             {
  156.                 if (option == 1)
  157.                 {
  158.                     int takequantity;
  159.                     printf("\n\tEnter Your Updated Quantity: ");
  160.                     scanf("%d",&takequantity);
  161.                     temp -> quantity = takequantity;
  162.                     printf("\n\t== Successfully Updated The Quantity ==\n");
  163.                 }
  164.  
  165.                 else if (option == -1)
  166.                 {
  167.                     int newprice;
  168.                     printf("\n\tEnter The New Price: ");
  169.                     scanf("%d",&newprice);
  170.                     temp -> price = newprice;
  171.                     printf("\n\t== Successfully Revise The Price ==\n");
  172.                 }
  173.  
  174.                 else if (option == 2)
  175.                 {
  176.                     snackstemp = temp -> nextsnacks;
  177.                     temp -> nextsnacks = snackstemp -> nextsnacks;
  178.                     free(snackstemp);
  179.                     sheadvariable -> counter --;
  180.                     printf("\n\t== Successfully Removed An Item ==\n");
  181.                 }
  182.             }
  183.             traverse (temp -> nextsnacks, take, option, catagory);
  184.         }
  185.     }
  186.  
  187.     else if (catagory == 2)
  188.     {
  189.         if (temp != NULL)
  190.         {
  191.             cnt++;
  192.             if (cnt == take)
  193.             {
  194.                 if (option == 1)
  195.                 {
  196.                     int takequantity;
  197.                     printf("\n\tEnter Your Updated Quantity: ");
  198.                     scanf("%d",&takequantity);
  199.                     temp -> quantity = takequantity;
  200.                     printf("\n\t== Successfully Updated The Quantity ==\n");
  201.                 }
  202.  
  203.                 else if (option == -1)
  204.                 {
  205.                     int newprice;
  206.                     printf("\n\tEnter The New Price: ");
  207.                     scanf("%d",&newprice);
  208.                     temp -> price = newprice;
  209.                     printf("\n\t== Successfully Revise The Price ==\n");
  210.                 }
  211.  
  212.                 else if (option == 2)
  213.                 {
  214.                     mealstemp = temp -> nextmeals;
  215.                     temp -> nextmeals = mealstemp -> nextmeals;
  216.                     free(mealstemp);
  217.                     mheadvariable -> counter --;
  218.                     printf("\n\t== Successfully Removed An Item ==\n");
  219.                 }
  220.             }
  221.             traverse (temp -> nextmeals, take, option, catagory);
  222.         }
  223.     }
  224.  
  225.     else if (catagory == 3)
  226.     {
  227.         if (temp != NULL)
  228.         {
  229.             cnt++;
  230.             if (cnt == take)
  231.             {
  232.                 if (option == 1)
  233.                 {
  234.                     int takequantity;
  235.                     printf("\n\tEnter Your Updated Quantity: ");
  236.                     scanf("%d",&takequantity);
  237.                     temp -> quantity = takequantity;
  238.                     printf("\n\t== Successfully Updated The Quantity ==\n");
  239.                 }
  240.  
  241.                 else if (option == -1)
  242.                 {
  243.                     int newprice;
  244.                     printf("\n\tEnter The New Price: ");
  245.                     scanf("%d",&newprice);
  246.                     temp -> price = newprice;
  247.                     printf("\n\t== Successfully Revise The Price ==\n");
  248.                 }
  249.  
  250.                 else if (option == 2)
  251.                 {
  252.                     drinkstemp = temp -> nextdrinks;
  253.                     temp -> nextdrinks = drinkstemp -> nextdrinks;
  254.                     free(drinkstemp);
  255.                     dheadvariable -> counter --;
  256.                     printf("\n\t== Successfully Removed An Item ==\n");
  257.                 }
  258.             }
  259.             traverse (temp -> nextdrinks, take, option, catagory);
  260.         }
  261.     }
  262. }
  263.  
  264. int main()
  265. {
  266.     sheadvariable = (struct head*) malloc(sizeof (struct head));
  267.     sheadvariable -> counter = 0;
  268.     sheadvariable -> pointer = NULL;
  269.  
  270.     mheadvariable = (struct head*) malloc(sizeof (struct head));
  271.     mheadvariable -> counter = 0;
  272.     mheadvariable -> pointer = NULL;
  273.  
  274.     dheadvariable = (struct head*) malloc(sizeof (struct head));
  275.     dheadvariable -> counter = 0;
  276.     dheadvariable -> pointer = NULL;
  277.  
  278.     printf("\n\t*************** WELCOME TO THE SUPER RESTURENT ***************\n");
  279.     printf("\t--------------------------------------------------------------\n");
  280.  
  281.     mainmenu:
  282.  
  283.     int user_choice;
  284.     string password;
  285.     char takepass;
  286.  
  287.     printf("\nUsers:\n");
  288.     printf("\t1 = Admin\n\t2 = Customer\n\t0 = Exit\n\n");
  289.     printf("\tYour Choice: ");
  290.     scanf("%d",&user_choice);
  291.  
  292.     if (user_choice == 1)
  293.     {
  294.         printf("\n\tPlease Enter The Password (Maximum Length 8): ");
  295.         takepass = _getch();
  296.         while (takepass != 13)
  297.         {
  298.             password.push_back(takepass);
  299.             printf("*");
  300.             takepass = _getch();
  301.         }
  302.         printf("\n\n");
  303.         if (password == "1234")
  304.         {
  305.             adminlevel:
  306.             int adminchoice, takecategory, takenumber;
  307.             printf("\t1 = Add a New Item.\n");
  308.             printf("\t2 = Update Some Quantity.\n");
  309.             printf("\t3 = Revise Some Price.\n");
  310.             printf("\t4 = Remove Some Item.\n");
  311.             printf("\t5 = Display The Menu.\n");
  312.             printf("\t6 = Return Main Menu.\n");
  313.             printf("\n\tEnter Your Choice: ");
  314.             scanf("%d",&adminchoice);
  315.  
  316.             if (adminchoice == 1)
  317.                 creat();
  318.  
  319.             else if (adminchoice == 2 || adminchoice == 3 || adminchoice == 4)
  320.             {
  321.                 display();
  322.                 printf("\n\tPlease Choose The Number of Your Required Item: ");
  323.                 scanf("%d",&takenumber);
  324.                 if (choice == 1)
  325.                 {
  326.                     cnt = 0;
  327.                     if (adminchoice == 2)
  328.                         traverse(sheadvariable -> pointer, takenumber, 1, choice);
  329.                     else if (adminchoice == 3)
  330.                         traverse(sheadvariable -> pointer, takenumber, -1, choice);
  331.                     else if (adminchoice == 4)
  332.                     {
  333.                         if (takenumber == 1)
  334.                         {
  335.                             snackstemp = sheadvariable -> pointer;
  336.                             sheadvariable -> pointer = sheadvariable -> pointer -> nextsnacks;
  337.                             free(snackstemp);
  338.                             sheadvariable -> counter --;
  339.                             printf("\n\t== Successfully Removed An Item ==\n");
  340.                         }
  341.                         else
  342.                             traverse(sheadvariable -> pointer, --takenumber, 2, choice);
  343.                     }
  344.                 }
  345.  
  346.                 else if (choice == 2)
  347.                 {
  348.                     cnt = 0;
  349.                     if (adminchoice == 2)
  350.                         traverse(mheadvariable -> pointer, takenumber, 1, choice);
  351.                     else if (adminchoice == 3)
  352.                         traverse(mheadvariable -> pointer, takenumber, -1, choice);
  353.                     else if (adminchoice == 4)
  354.                     {
  355.                         if (takenumber == 1)
  356.                         {
  357.                             mealstemp = mheadvariable -> pointer;
  358.                             mheadvariable -> pointer = mheadvariable -> pointer -> nextmeals;
  359.                             free(mealstemp);
  360.                             mheadvariable -> counter --;
  361.                             printf("\n\t== Successfully Removed An Item ==\n");
  362.                         }
  363.                         else
  364.                             traverse(mheadvariable -> pointer, --takenumber, 2, choice);
  365.                     }
  366.                 }
  367.  
  368.                 else if (choice == 3)
  369.                 {
  370.                     cnt = 0;
  371.                     if (adminchoice == 2)
  372.                         traverse(dheadvariable -> pointer, takenumber, 1, choice);
  373.                     else if (adminchoice == 3)
  374.                         traverse(dheadvariable -> pointer, takenumber, -1, choice);
  375.                     else if (adminchoice == 4)
  376.                     {
  377.                         if (takenumber == 1)
  378.                         {
  379.                             drinkstemp = dheadvariable -> pointer;
  380.                             dheadvariable -> pointer = dheadvariable -> pointer -> nextdrinks;
  381.                             free(drinkstemp);
  382.                             dheadvariable -> counter --;
  383.                             printf("\n\t== Successfully Removed An Item ==\n");
  384.                         }
  385.                         else
  386.                             traverse(dheadvariable -> pointer, --takenumber, 2, choice);
  387.                     }
  388.                 }
  389.             }
  390.  
  391.             else if (adminchoice == 5)
  392.                 display();
  393.  
  394.             else if (adminchoice == 6)
  395.                 goto mainmenu;
  396.  
  397.             printf("\n");
  398.             goto adminlevel;
  399.         }
  400.         else
  401.         {
  402.             printf("\tInvalid Password! You Cannot Access This Feature.\n");
  403.             goto mainmenu;
  404.         }
  405.     }
  406.  
  407.     else if (user_choice == 0)
  408.     {
  409.         printf("\n\tThank You.\n");
  410.         return 0;
  411.     }
  412.  
  413.     else
  414.     {
  415.         printf("\n\tUnknown Option. Please Try Again.\n");
  416.         goto mainmenu;
  417.     }
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement