Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.90 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!=""){
  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.             cin>>item_name;
  107.          // if user's input matches with item name in the inventory, the customer can add the item to cart.
  108.             if(item_name==name[i] && stock[i]!=0){
  109.             cout<<"\t\tThe item "<<name[i]<< " is available"<<endl;
  110.             cout<<"\t\tEnter number of "<<name[i]<< " to buy "<<endl;
  111.             cin>>quantity[i]; //prompts user to enter number of desired items to add to cart
  112.             stock[i]-=quantity[i]; // Removed quantity purchased from stock.
  113.             cart[i]=name[i]; //Adds item name to cart
  114.             cout<<"\t\tItem "<<name[i]<<"is added to cart"<<endl;
  115.         }
  116.              else if(item_name==name[i]&&stock[i]==0){
  117.             cout<<"\t\tThe item is currently out of stock"<<endl;
  118.         }
  119.  
  120.          // if user's input does not match with item name in the inventory, it exits that iteration and starts iterating again.
  121.             else if(item_name!=name[i]&&stock[i]!=0){
  122.                continue;
  123.             }
  124.  
  125.       }
  126.           cout<<"Hit 0 to go back to main menu"<<endl;
  127.           cin>>go;
  128.           if(go==0)
  129.             menu(); //function call that allows user to return to main menu
  130.  
  131.    }
  132.  
  133.     //Generates a bill report that calculates total price of items added to cart
  134.    void bill(string name[], double price[], string cart[],int quantity[],int no[], int arraySize){
  135.       total=0;
  136.  
  137.         cout<<"\n\n\t\t*******************************************************";
  138.         cout<<"\n\n\t\t                     BILL DETAILS";
  139.         cout<<"\n\n\t\t*******************************************************";
  140.         cout<<"\n\n";
  141.         cout<<"\t\t     Name\tQuantity\tPrice"<<endl;
  142.        for(i=0; i<n;i++){
  143.             // If item name in cart does not match with item name in inventory, it exits that specific iteration and starts iterating again.
  144.             if(cart[i]!=name[i]){
  145.                 continue;
  146.             }
  147.         // If item name in cart matches with item name in inventory, it adds the price of that item to total price.
  148.         else if(cart[i]==name[i]){
  149.             total=total+price[i]; // Calculates total price of all items in cart
  150.             cout<<"\t\t\t"<<name[i]<<"\t"<<quantity[i]<<"\t"<<price[i]<<endl;
  151.         }
  152.        }
  153.          cout<<"\n\n\t\t*******************************************************";
  154.         cout<<"\n\n\t\t                           Total Amount: RM."<<total<<"  "; //Shows total price
  155.         cout<<"\n\n\t\t*******************************************************";
  156.  
  157.           cout<<"Hit 0 to go back to main menu"<<endl;
  158.           cin>>go;
  159.           if(go==0)
  160.             menu(); //function call that allows user to return to main menu
  161.  
  162.    }
  163.  
  164.   //Shows options available to user to navigate on the console
  165.    void menu(){
  166.           cout<<"\n\n";
  167.         cout<<"\t1. Add items\n";
  168.         cout<<"\t2. Show available items\n";
  169.         cout<<"\t3. Shop items\n";
  170.         cout<<"\t4. Generate bill report\n";
  171.         cout<<"\t5. Exit\n";
  172.         cout<<"\tchoice: ";
  173.    }
  174.  
  175.  
  176. };
  177.  
  178. int main()
  179. {
  180.  
  181.     int arraySize=20;  // specifies size of each variable declared
  182.     int no[arraySize]; // number of items in inventory
  183.     string name[arraySize]; //item names in inventory
  184.     string date[arraySize];// item manufacturing date
  185.     double price[arraySize];// price of item in inventory
  186.     int stock[arraySize]; // stock available for each item
  187.     string cart[arraySize]; // item name added to cart
  188.     int quantity[arraySize];// quantity of each item purchased
  189.     int choice; //allows user to navigate through menu
  190.  
  191.     Super obj; // Creates an object for class super
  192.  
  193.    obj.menu();
  194.     do{
  195.  
  196.         cin>>choice;
  197.  
  198.         switch(choice){
  199.         case 1:
  200.             obj.add_items(no, name, date, price, stock, arraySize); // function call that allows administrator to add item to inventory
  201.             break;
  202.         case 2:
  203.             obj.display_items(no, name, date, price, stock, arraySize); //function call that allows to display all items
  204.             break;
  205.         case 3:
  206.             obj.shop_items(name, stock, cart, quantity, arraySize); //function call that allows user to purchase items from inventory
  207.             break;
  208.         case 4:
  209.             obj.bill(name, price, cart,quantity, no, arraySize); //function call that generates final billing report for items in cart
  210.             break;
  211.         case 5:
  212.              system("cls");
  213.             cout<<"\n\n\t\tThank you for shopping. Do come Again ! \n\n";
  214.             break;
  215.  
  216.         }
  217.  
  218.  
  219.     }while(choice != 6);// do end
  220.  
  221.     return 0;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement