Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Description:
- /**
- ** A supermarket console application that allows administrators to add items, change stocks in order to let
- ** customers purchase desired item.
- ** Customers can display the items, check prices and quantity.
- ** The application allows customer to add desired items into cart and eventually generate a full billing report.
- */
- // Authors
- /**
- Name: Rezwan Sheikh
- ID - 0332268
- Name : Ashiqur Rahman Hrithik
- ID - 0332301
- */
- //Included Libraries
- #include <iostream>
- #include<cstdlib>
- using namespace std; //using standard namespace
- class Super{
- public:
- int i; //for loop iterator
- int n; //number of items available in inventory
- double total; //total price of item purchased
- int go; // variable used to return to main menu
- //Constructor used to initialize total to 0
- super(){
- total=0;
- }
- //function used to add items to inventory
- void add_items(int no[], string name[], string date[], double price[], int stock[], int arraySize){
- string userName;
- string pass;
- cout<<"\t\tEnter administrator login name\t\t"<<endl;
- cout <<"\t\t";
- cin>>userName;
- cout<<"\t\tEnter administrator password\t\t"<<endl;
- cout << "\t\t";
- cin>>pass;
- if(userName != "Admin" &&pass!=""){
- cout<<"Login Unsuccessful! Adding items is only for administrators"<<endl;
- menu();}
- else{
- cout<<"\n\t\tAdd number of items to be added: ";
- cin>>n;
- // loop that allows information to be entered for each item. Terminates at the last item.
- for(i=0;i<n;i++){
- cout<<"\n";
- cout<<"\t\t****** Item Details ******\n\n";
- cout<<"\t\tItem number: ";
- cin>>no[i];
- cout<<"\t\tItem name: ";
- cin>>name[i];
- cout<<"\t\tManufacturing date: ";
- cin>>date[i];
- cout<<"\t\tPrice: ";
- cin>>price[i];
- cout<<"\t\tStock: ";
- cin>>stock[i];
- }
- cout<<"Hit 0 to go back to main menu"<<endl;
- cin>>go;
- if(go==0)
- menu(); //function call that allows user to return to main menu
- }
- }
- // Displays the items and its information in the inventory.
- void display_items(int no[], string name[], string date[], double price[], int stock[], int arraySize){
- cout<<"\n\n\t\tAvailable Items: \n\n";
- for(i=0; i<n; i++){
- //Displays all information for each item
- cout<<"\t\tItem No: "<<no[i];
- cout<<"\n\t\tItem Name: "<<name[i];
- cout<<"\n\t\tManufacturing date: "<<date[i];
- cout<<"\n\t\tPrice: "<<price[i];
- cout<<"\n\t\tStock: "<<stock[i];
- cout<<"\n\n";
- }
- cout<<"\t\tHit 0 to go back to main menu"<<endl;
- cin>>go;
- if(go==0)
- menu(); //Function call that allows the user to return to main menu
- }
- //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.
- void shop_items(string name[], int stock[], string cart[],int quantity[], int arraySize ){
- string item_name;
- for(i=0;i<n;i++){
- cout<<"\t\tEnter name of item"<<endl;
- cin>>item_name;
- // if user's input matches with item name in the inventory, the customer can add the item to cart.
- if(item_name==name[i] && stock[i]!=0){
- cout<<"\t\tThe item "<<name[i]<< " is available"<<endl;
- cout<<"\t\tEnter number of "<<name[i]<< " to buy "<<endl;
- cin>>quantity[i]; //prompts user to enter number of desired items to add to cart
- stock[i]-=quantity[i]; // Removed quantity purchased from stock.
- cart[i]=name[i]; //Adds item name to cart
- cout<<"\t\tItem "<<name[i]<<"is added to cart"<<endl;
- }
- else if(item_name==name[i]&&stock[i]==0){
- cout<<"\t\tThe item is currently out of stock"<<endl;
- }
- // if user's input does not match with item name in the inventory, it exits that iteration and starts iterating again.
- else if(item_name!=name[i]&&stock[i]!=0){
- continue;
- }
- }
- cout<<"Hit 0 to go back to main menu"<<endl;
- cin>>go;
- if(go==0)
- menu(); //function call that allows user to return to main menu
- }
- //Generates a bill report that calculates total price of items added to cart
- void bill(string name[], double price[], string cart[],int quantity[],int no[], int arraySize){
- total=0;
- cout<<"\n\n\t\t*******************************************************";
- cout<<"\n\n\t\t BILL DETAILS";
- cout<<"\n\n\t\t*******************************************************";
- cout<<"\n\n";
- cout<<"\t\t Name\tQuantity\tPrice"<<endl;
- for(i=0; i<n;i++){
- // If item name in cart does not match with item name in inventory, it exits that specific iteration and starts iterating again.
- if(cart[i]!=name[i]){
- continue;
- }
- // If item name in cart matches with item name in inventory, it adds the price of that item to total price.
- else if(cart[i]==name[i]){
- total=total+price[i]; // Calculates total price of all items in cart
- cout<<"\t\t\t"<<name[i]<<"\t"<<quantity[i]<<"\t"<<price[i]<<endl;
- }
- }
- cout<<"\n\n\t\t*******************************************************";
- cout<<"\n\n\t\t Total Amount: RM."<<total<<" "; //Shows total price
- cout<<"\n\n\t\t*******************************************************";
- cout<<"Hit 0 to go back to main menu"<<endl;
- cin>>go;
- if(go==0)
- menu(); //function call that allows user to return to main menu
- }
- //Shows options available to user to navigate on the console
- void menu(){
- cout<<"\n\n";
- cout<<"\t1. Add items\n";
- cout<<"\t2. Show available items\n";
- cout<<"\t3. Shop items\n";
- cout<<"\t4. Generate bill report\n";
- cout<<"\t5. Exit\n";
- cout<<"\tchoice: ";
- }
- };
- int main()
- {
- int arraySize=20; // specifies size of each variable declared
- int no[arraySize]; // number of items in inventory
- string name[arraySize]; //item names in inventory
- string date[arraySize];// item manufacturing date
- double price[arraySize];// price of item in inventory
- int stock[arraySize]; // stock available for each item
- string cart[arraySize]; // item name added to cart
- int quantity[arraySize];// quantity of each item purchased
- int choice; //allows user to navigate through menu
- Super obj; // Creates an object for class super
- obj.menu();
- do{
- cin>>choice;
- switch(choice){
- case 1:
- obj.add_items(no, name, date, price, stock, arraySize); // function call that allows administrator to add item to inventory
- break;
- case 2:
- obj.display_items(no, name, date, price, stock, arraySize); //function call that allows to display all items
- break;
- case 3:
- obj.shop_items(name, stock, cart, quantity, arraySize); //function call that allows user to purchase items from inventory
- break;
- case 4:
- obj.bill(name, price, cart,quantity, no, arraySize); //function call that generates final billing report for items in cart
- break;
- case 5:
- system("cls");
- cout<<"\n\n\t\tThank you for shopping. Do come Again ! \n\n";
- break;
- }
- }while(choice != 6);// do end
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement