Question

In: Computer Science

Write the program with language C++ ( THE PROGRAM SHOULD CONTAIN DECISION MAKING , LOOPING AND...

Write the program with language C++ ( THE PROGRAM SHOULD CONTAIN DECISION MAKING , LOOPING AND A FUNCTION ) to design a menu for a shop . When the user makes a choice , ask for quantity, then display the total charge with sale taxes . If the user enters a choice that is unavailable ,display an error message and ask him to re-enter.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

#include <iostream>
using namespace std;

// function to display menu.
void menu()
{
    cout<<"\n1. Show items\n";
    cout<<"2. Buy an item\n";
    cout<<"3. checkout\n";
    cout<<"Please enter your choice: ";
}

// function to display all the items.
void show_items()
{
    // Let's say only 2 items are available
    cout<<"Available items in the shop are:\n";
    cout<<"\t1. Pen ( 5 Rupees each )\n";
    cout<<"\t2. Pencil ( 3 Rupees each )\n";
}

int main()
{
   // declare variables
   double total=0;
   // LOOP HERE
   while(1)
   {
        // print menu
        menu();
        // read the choice
        int ch;
        cin>>ch;
      
        // DECISION MAKING USING IF ELSE
        if(ch==1)
        {
            show_items();
        }
        else if(ch==2)
        {
            show_items();
            cout<<"\nPlease enter the item number: ";
            int item;
            cin>>item;
            if(item==1)
            {
                cout<<"Enter the Quantity of pens: ";
                int quantity;
                cin>>quantity;
                cout<<quantity<<" Pens Successfully added to your cart."<<endl;
                cout<<"The cost of "<<quantity<<" pens is: "<<quantity*5;
                // add it to total
                total += quantity*5;
            }
            else if(item==2)
            {
                cout<<"Enter the Quantity of Pencils: ";
                int quantity;
                cin>>quantity;
                cout<<quantity<<" Pencils Successfully added to your cart."<<endl;
                cout<<"The cost of "<<quantity<<" pencils is: "<<quantity*3;
                // add it to total
                total += quantity*5;
            }
            else
            {
                cout<<"Invalid Choice";
            }
              
        }
        else if(ch==3)
        {
            cout<<"\n\nThank You for shopping. Your total bill is:\n";
            cout<<"Total Price: "<<total<<endl;
            // add 10% tax
            cout<<"Sales Tax: "<<total*0.1<<endl;
            cout<<"FINAL BILL: "<<total + total*0.1 <<endl;
            break;
        }
        else
        {
             cout<<"Invalid Choice. Please Try again..!!";
        }
   }
   return 0;
}

========


OUTPUT


Related Solutions

Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
Write a program that uses an array for time and temperature. The program should contain an...
Write a program that uses an array for time and temperature. The program should contain an array with 24 elements, each of which is holding a temperature for a single hour. Your program should have a function that lists all of the temperatures that are held in the array. Temperatures should be listed to console with one entry per line. Your program should have a function that lists a single temperature entry. You should ask the user for a number...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Write a C++ program test.cpp. The class should contain a protected int member variable var, which...
Write a C++ program test.cpp. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called play that should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var. The function f is defined as f(x) = (3x+1)/2 if x is odd...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
For decentralized decision making to be successful, it should be predicated on a belief that decision-making...
For decentralized decision making to be successful, it should be predicated on a belief that decision-making authority should be pushed down to the lowest organizational level capable of making timely, informed, competent decisions. Do you agree or disagree? Why? Cite an example that helps defend your position
For decentralized decision making to be successful, it should be predicated on a belief that decision-making...
For decentralized decision making to be successful, it should be predicated on a belief that decision-making authority should be pushed down to the lowest organizational level capable of making timely, informed, competent decisions. Do you agree or disagree? Why? Cite an example that helps defend your position.
Project Outcomes: Develop a python program that uses:  decision constructs  looping constructs  basic...
Project Outcomes: Develop a python program that uses:  decision constructs  looping constructs  basic operations on an list of objects (find, change, access all elements)  more than one class and has multiple objects Project Requirements: 1. Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room class. The Hotel class will contain several Room objects and will have several operations. We will also have a driver program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT