Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.97 KB | None | 0 0
  1. //  Description:
  2. /**
  3. **  A supermarket console application that allows administrators to add items, change stocks in order to let
  4. **  customers purchase desired item.
  5. **  Customers can display the items, check prices and quantity.
  6. **  The application allows customer to add desired items into cart and eventually generate a full billing report.
  7. */
  8.  
  9. //  Authors
  10. /**
  11.     Name: Rezwan Sheikh
  12.     ID - 0332268
  13.     Name : Ashiqur Rahman Hrithik
  14.     ID - 0332301
  15. */
  16.  
  17. //Included Libraries
  18. #include <iostream>
  19. #include<cstdlib>
  20.  
  21.  
  22.  
  23. using namespace std; //using standard namespace
  24.  
  25. class Super{
  26.     public:
  27.     int i; //for loop iterator
  28.     int n; //number of items available in inventory
  29.     double total; //total price of item purchased
  30.     int go; // variable used to return to main menu
  31.  
  32.    //Constructor used to initialize total to 0
  33.    super(){
  34.    total=0;
  35.  
  36.    }
  37.     //function used to add items to inventory
  38.     void add_items(int no[], string name[], string date[], double price[], int stock[], int arraySize){
  39.  
  40.         string userName;
  41.         string pass;
  42.         cout<<"\t\tEnter administrator login name\t\t"<<endl;
  43.         cout <<"\t\t";
  44.         cin>>userName;
  45.         cout<<"\t\tEnter administrator password\t\t"<<endl;
  46.         cout << "\t\t";
  47.         cin>>pass;
  48.         if(userName != "Admin" && pass!="1234"){
  49.                 cout<<"Login Unsuccessful! Adding items is only for administrators"<<endl;
  50.                 menu();}
  51.            else{
  52.         cout<<"\n\t\tAdd number of items to be added: ";
  53.         cin>>n;
  54.  
  55.         // loop that allows information to be entered for each item. Terminates at the last item.
  56.         for(i=0;i<n;i++){
  57.             cout<<"\n";
  58.             cout<<"\t\t****** Item Details ******\n\n";
  59.             cout<<"\t\tItem number: ";
  60.             cin>>no[i];
  61.             cout<<"\t\tItem name: ";
  62.             cin>>name[i];
  63.             cout<<"\t\tManufacturing date: ";
  64.             cin>>date[i];
  65.             cout<<"\t\tPrice: ";
  66.             cin>>price[i];
  67.             cout<<"\t\tStock: ";
  68.             cin>>stock[i];
  69.         }
  70.           cout<<"Hit 0 to go back to main menu"<<endl;
  71.           cin>>go;
  72.           if(go==0)
  73.             menu(); //function call that allows user to return to main menu
  74.           }
  75.     }
  76.     // Displays the items and its information in the inventory.
  77.     void display_items(int no[], string name[], string date[], double price[], int stock[], int arraySize){
  78.  
  79.         cout<<"\n\n\t\tAvailable Items: \n\n";
  80.  
  81.         for(i=0; i<n; i++){
  82.  
  83.             //Displays all information for each item
  84.             cout<<"\t\tItem No:  "<<no[i];
  85.             cout<<"\n\t\tItem Name: "<<name[i];
  86.             cout<<"\n\t\tManufacturing date: "<<date[i];
  87.             cout<<"\n\t\tPrice: "<<price[i];
  88.             cout<<"\n\t\tStock: "<<stock[i];
  89.             cout<<"\n\n";
  90.         }
  91.  
  92.           cout<<"\t\tHit 0 to go back to main menu"<<endl;
  93.           cin>>go;
  94.           if(go==0)
  95.             menu(); //Function call that allows the user to return to main menu
  96.  
  97.  
  98.     }
  99.  
  100.         //Allows user to search individual items. If item name matches user's input and its stock is not zero, the user can purchase the item.
  101.        void shop_items(string name[], int stock[], string cart[],int quantity[], int arraySize ){
  102.        string item_name;
  103.  
  104.       for(i=0;i<n;i++){
  105.             cout<<"\t\tEnter name of item"<<endl;
  106.             cout<<"\t\t";
  107.             cin>>item_name;
  108.          // if user's input matches with item name in the inventory, the customer can add the item to cart.
  109.             if(item_name==name[i] && stock[i]!=0){
  110.             cout<<"\t\tThe item "<<name[i]<< " is available"<<endl;
  111.             cout<<"\t\tEnter number of "<<name[i]<< " to buy "<<endl;
  112.             cin>>quantity[i]; //prompts user to enter number of desired items to add to cart
  113.             stock[i]-=quantity[i]; // Removed quantity purchased from stock.
  114.             cart[i]=name[i]; //Adds item name to cart
  115.             cout<<"\t\tItem "<<name[i]<<"is added to cart"<<endl;
  116.         }
  117.              else if(item_name==name[i]&&stock[i]==0){
  118.             cout<<"\t\tThe item is currently out of stock"<<endl;
  119.         }
  120.  
  121.          // if user's input does not match with item name in the inventory, it exits that iteration and starts iterating again.
  122.             else if(item_name!=name[i]&&stock[i]!=0){
  123.                continue;
  124.             }
  125.  
  126.       }
  127.           cout<<"\t\tHit 0 to go back to main menu"<<endl;
  128.           cout <<"\t\t";
  129.           cin>>go;
  130.           if(go==0)
  131.             menu(); //function call that allows user to return to main menu
  132.  
  133.    }
  134.  
  135.     //Generates a bill report that calculates total price of items added to cart
  136.    void bill(string name[], double price[], string cart[],int quantity[],int no[], int arraySize){
  137.       total=0;
  138.  
  139.         cout<<"\n\n\t\t*******************************************************";
  140.         cout<<"\n\n\t\t                     BILL DETAILS";
  141.         cout<<"\n\n\t\t*******************************************************";
  142.         cout<<"\n\n";
  143.         cout<<"\t\t     Name\tQuantity\tPrice"<<endl;
  144.        for(i=0; i<n;i++){
  145.             // If item name in cart does not match with item name in inventory, it exits that specific iteration and starts iterating again.
  146.             if(cart[i]!=name[i]){
  147.                 continue;
  148.             }
  149.         // If item name in cart matches with item name in inventory, it adds the price of that item to total price.
  150.         else if(cart[i]==name[i]){
  151.             total=total+price[i]; // Calculates total price of all items in cart
  152.             cout<<"\t\t\t"<<name[i]<<"\t"<<quantity[i]<<"\t"<<price[i]<<endl;
  153.         }
  154.        }
  155.          cout<<"\n\n\t\t*******************************************************";
  156.         cout<<"\n\n\t\t                           Total Amount: RM."<<total<<"  "; //Shows total price
  157.         cout<<"\n\n\t\t*******************************************************";
  158.  
  159.           cout<<"\n\t\tHit 0 to go back to main menu"<<endl;
  160.           cin>>go;
  161.           if(go==0)
  162.             menu(); //function call that allows user to return to main menu
  163.  
  164.    }
  165.  
  166.   //Shows options available to user to navigate on the console
  167.    void menu(){
  168.           cout<<"\n\n";
  169.         cout<<"\t1. Add items\n";
  170.         cout<<"\t2. Show available items\n";
  171.         cout<<"\t3. Shop items\n";
  172.         cout<<"\t4. Generate bill report\n";
  173.         cout<<"\t5. Exit\n";
  174.         cout<<"\tchoice: ";
  175.    }
  176.  
  177.  
  178. };
  179.  
  180. int main()
  181. {
  182.  
  183.     int arraySize=20;  // specifies size of each variable declared
  184.     int no[arraySize]; // number of items in inventory
  185.     string name[arraySize]; //item names in inventory
  186.     string date[arraySize];// item manufacturing date
  187.     double price[arraySize];// price of item in inventory
  188.     int stock[arraySize]; // stock available for each item
  189.     string cart[arraySize]; // item name added to cart
  190.     int quantity[arraySize];// quantity of each item purchased
  191.     int choice; //allows user to navigate through menu
  192.  
  193.     Super obj; // Creates an object for class super
  194.  
  195.    obj.menu();
  196.     do{
  197.  
  198.         cin>>choice;
  199.  
  200.         switch(choice){
  201.         case 1:
  202.             obj.add_items(no, name, date, price, stock, arraySize); // function call that allows administrator to add item to inventory
  203.             break;
  204.         case 2:
  205.             obj.display_items(no, name, date, price, stock, arraySize); //function call that allows to display all items
  206.             break;
  207.         case 3:
  208.             obj.shop_items(name, stock, cart, quantity, arraySize); //function call that allows user to purchase items from inventory
  209.             break;
  210.         case 4:
  211.             obj.bill(name, price, cart,quantity, no, arraySize); //function call that generates final billing report for items in cart
  212.             break;
  213.         case 5:
  214.              system("cls");
  215.             cout<<"\n\n\t\tThank you for shopping. Do come Again ! \n\n";
  216.             break;
  217.  
  218.         }
  219.  
  220.  
  221.     }while(choice != 6);// do end
  222.  
  223.     return 0;
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement