Question

In: Computer Science

Using C++ write a program to calculate the amount a customer should pay in a self...

Using C++ write a program to calculate the amount a customer should pay in a self checkout counter for his purchases in a bagel shop. The products sold are everything bagels, garlic bagels, blueberry bagels, cream cheese, and coffee. Using "doWhile loops" write the program to display the menu of the Bagel shop. Make the user buy multiple items of different choices. Finally display the total amount for the purchases. Below is my current code to work with. Please add comments to help me understand the code.

//This program implements bagel shop PoS
#include <iostream>
#include <iomanip>

using namespace std;

const float EVERY_BAGEL_COST = 1.99;
const float BLUE_BAGEL_COST = 1.99;
const float GARLIC_BAGEL_COST = 1.99;
const float CREAM_CHEESE_COST = 2.99;
const float COFFEE_COST = 3.99;

int main()

{

    char choice;
    int cnt;

    double total_charges = 0.0;
    double charges_every = 0.0;
    double charges_blueberry = 0.0;
    double charges_garlic = 0.0;
    double charges_cream = 0.0;
    double charges_coffee = 0.0;
    cout << fixed << showpoint << setprecision(2);

    cout << "Please pick one item from the menu:" << endl
    << endl;
    cout << "Enter A for Everything Bagel" << endl;
    cout << "Enter B for Blueberry Bagel" << endl;
    cout << "Enter C for Garlic Bagel" << endl;
    cout << "Enter D for Cream Cheese" << endl;
    cout << "Enter E for coffee" << endl;
    cout << "Enter F for quit" << endl
    << endl;

    do

    {
    // get the choice from A to F
    cout << "\nEnter your choice of food: ";
    cin >> choice;

    switch (choice)

    {

    case 'A':

    cout << "Enter number of items : ";
    cin >> cnt;

    charges_every += (EVERY_BAGEL_COST * cnt);

    break;

    case 'B':

    cout << "Enter number of items : ";
    cin >> cnt;

    charges_blueberry += (BLUE_BAGEL_COST * cnt);

    break;

    case 'C':

    cout << "Enter number of items : ";
    cin >> cnt;

    charges_garlic += (GARLIC_BAGEL_COST * cnt);

    break;

    case 'D':

    cout << "Enter number of items : ";
    cin >> cnt;

    charges_cream += (CREAM_CHEESE_COST * cnt);

    break;

    case 'E':

    cout << "Enter number of items : ";
    cin >> cnt;

    charges_coffee += (COFFEE_COST * cnt);

    break;

    case 'F':

    break;

    default:

    cout << "Enter a choice between A to F" << endl;

    }

    } while (choice != 'F');

    total_charges = charges_every + charges_coffee +

    charges_cream + charges_blueberry +

    charges_garlic;

    cout << "\nEverything Bagel : $" << charges_every << endl;

    cout << "\nBlueberry Bagel : $" << charges_blueberry << endl;

    cout << "\nGarlic Bagel : $" << charges_garlic << endl;

    cout << "\nCream Cheese : $" << charges_cream << endl;

    cout << "\ncoffee : $" << charges_coffee << endl;

    cout << "\nTotal charges are: $" << total_charges << endl;

    cout << endl;


    return 0;
}

Solutions

Expert Solution

//################# PGM START #################################

//This program implements bagel shop PoS
#include <iostream>
#include <iomanip>

using namespace std;

const float EVERY_BAGEL_COST = 1.99;
const float BLUE_BAGEL_COST = 1.99;
const float GARLIC_BAGEL_COST = 1.99;
const float CREAM_CHEESE_COST = 2.99;
const float COFFEE_COST = 3.99;

int main()
{

    char choice;
    int cnt;

    double total_charges = 0.0;
    double charges_every = 0.0;
    double charges_blueberry = 0.0;
    double charges_garlic = 0.0;
    double charges_cream = 0.0;
    double charges_coffee = 0.0;
    cout << fixed << showpoint << setprecision(2);

  
    //re[eat untill user want to exit (ie choice F)

    do

    {
       //menu items for user
       cout << "Please pick one item from the menu:" << endl;
       cout<<"______________________________________"<< endl;
       cout << "Enter A for Everything Bagel" << endl;
       cout << "Enter B for Blueberry Bagel" << endl;
       cout << "Enter C for Garlic Bagel" << endl;
       cout << "Enter D for Cream Cheese" << endl;
       cout << "Enter E for coffee" << endl;
       cout << "Enter F for quit" << endl<< endl;
      
        // get the choice from A to F
       cout << "\nEnter your choice of food: ";
       cin >> choice;
      
       cnt=0;
      
       //if the choice is fom A to E , get the number of items from user
       if(choice=='A' || choice=='B' || choice=='C' || choice=='D' || choice=='E'){
           cout << "Enter number of items : ";
           cin >> cnt;
           cin.ignore();
       }
  

       //for A to E calculate the cost
       switch (choice) {

            case 'A': charges_every += (EVERY_BAGEL_COST * cnt);
                      break;

           case 'B': charges_blueberry += (BLUE_BAGEL_COST * cnt);
                      break;

           case 'C': charges_garlic += (GARLIC_BAGEL_COST * cnt);
                      break;
          
           case 'D': charges_cream += (CREAM_CHEESE_COST * cnt);
                      break;
          
           case 'E': charges_coffee += (COFFEE_COST * cnt);
                      break;

           case 'F': break;
          
            default: cout << "Enter a choice between A to F" << endl;
       }  
       cout<<endl;
    } while (choice != 'F');

   //find the total charge
    total_charges = charges_every + charges_coffee +charges_cream + charges_blueberry +charges_garlic;

   //print the cost of each item and final amount
    cout << "\nEverything Bagel : $" << charges_every << endl;
    cout << "\nBlueberry Bagel : $" << charges_blueberry << endl;
    cout << "\nGarlic Bagel : $" << charges_garlic << endl;
    cout << "\nCream Cheese : $" << charges_cream << endl;
    cout << "\ncoffee : $" << charges_coffee << endl;
    cout << "\nTotal charges are: $" << total_charges << endl;
    cout << endl<<endl;

    return 0;
}


//##################### PGM END #######################

OUTPUT
###########


Related Solutions

Using C++ Write a program to calculate the amount a customer should pay in a checkout...
Using C++ Write a program to calculate the amount a customer should pay in a checkout counter for the purchases in a bagel shop. The products sold are bagels, cream cheese, and coffee. Use the pseudo code discussed in the class to write the program. Make reasonable assumptions about the prices of bagel, cream cheese, and coffee. Declare prices of bagel, cream cheese, and coffee as constants.
Overview For this assignment, write a program that will calculate the amount that a customer spends...
Overview For this assignment, write a program that will calculate the amount that a customer spends on tickets at a movie theater. This program will be continued in program 3 so it is important that this program is completed. Basic Program Logic The basic logic for this program is similar to program 1: the user is asked to enter values, a calculation is performed, and the result of the calculation is displayed. For this program, prompt the user for the...
Write a program to help a small company calculate the amount of money to pay its...
Write a program to help a small company calculate the amount of money to pay its employees. In this simplistic world, the company has exactly three employees. However, the number of hours per employee may vary. The company will apply the same tax rate to every employee The program must be written in Java. Prompt the user for the inputs and store the values in variables Must include all the inputs and outputs listed here and perform the calculations correctly...
Write a program in python to calculate the amount each person must pay toward the bill...
Write a program in python to calculate the amount each person must pay toward the bill and toward the tip, for a group of friends who are eating out together. Since you are all friends, it is okay to split the costs evenly. Your program should take as input: The restaurant bill (without tax or tip) as a floating point number The sales tax rate as a floating point number (for example: an 8% tax rate would be 0.08) The...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator. Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %. Output Requirements: Make your output easy to understand,...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
(Write a program in C++) A local instructor wants you to write a program to calculate...
(Write a program in C++) A local instructor wants you to write a program to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60...
in C++ Requirements: Write a program that creates a new class called Customer. The Customer class...
in C++ Requirements: Write a program that creates a new class called Customer. The Customer class should include the following private data: name - the customer's name, a string. phone - the customer's phone number, a string. email - the customer's email address, a string. In addition, the class should include appropriate accessor and mutator functions to set and get each of these values. Have your program create one Customer objects and assign a name, phone number, and email address...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program of question 1 using PTHREADS. Calculate time taken to execute program.(1 mark) Identify data races in above program and explain why this situation occurred with an example (1 mark) Rewrite the code to avoid data races should use any of the THREE techniques.(1.5 marks) please I need the c code.. critical section mutex solution semaphore functions Barriers Read-Write Locks Run program using 1, 2,...
A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT