The language is c++ and this how the output should look like. a Safari 9:49 AM C
ID: 3598133 • Letter: T
Question
The language is c++ and this how the output should look like.a Safari 9:49 AM Coffee Shop Project Part 2 For this part of the project you will do the following: (1) add input validation to the amount of coffee ordered, (2) modify the algorithm for determining types of cups needed to reduce the number of Shot cups used and (3) calculate the total price of the order based on the amount and type of coffee ordered. Use the table below to determine the price of the coffee. Product Cost per Ounce S0.2 acchiato . Modify your Part 1 code to display the numbers of each type of cup needed for the order only if the amount of coffee ordered is greater than 0. Otherwise, just display a descriptive error message. 2. Modify your Part I code that determines the number of each type of cup to reduce the number of Shot cups used. Add functionality to your program so that a Regular (8 oz) cup will be used instead of multiple Shot (1 oz) cups if the number of Shot cups needed exceeds 3. scription 3. Calculate the total cost of the order including tax and display a bill for the coffee. See the Sample Output. The current sales tax rate is 7%. Use named constants for the sales tax rate and the base cost of each type of coffee. 4. Add a menu to offer the user a choice between the different types of coffee. The menu should be the first thing displayed when your program begins executing. The menu format should match the one in the Sample Output on page 2. 5. Validate the user's menu choice. If the user enters any number other than 1, 2, 3 or 4 just display a descriptive error message. See Sample Output below for format.
Explanation / Answer
// OUTPUT
//------------ CODE -------------------//
#include <iostream>
//
#include<iomanip>
//
#include<cstring>
//
#include<cmath>
//
#define SALES_TAX_RATE 0.07 // the sales tax in percentage (7/100 = 0.07)
//
// rate constants for different coffee types
#define PLAIN_PER_OUNCE 0.13
//
#define LATTE_PER_OUNCE 0.23
//
#define MAC_PER_OUNCE 0.25
//
#define FRAP_PER_OUNCE 0.28
//
/// defines for the cup sizes, add more as per requirement
#define REGULAR_SIZE 8
//
#define SHOT_SIZE 1
//
using namespace std;
int main()
{
//
int choice, ounces, num_cups_shot = 0, num_cups_reg = 0, num_cups_verti = 0, num_cups_grande = 0, i;
//
float base_price, tax, total;
//
string customer_name, order;
//
char cus_name[30];
//
// display the menu and ask for user choice
cout << "Welcome to the World's Best Coffee Shop" << endl;
//
cout<<"1-Plain Coffee"<<endl<<"2-Latte"<<endl<<"3-Macchiato"<<endl<<"4-Frappuccino"<<endl;
//
cout<<"Enter your choice:";
//
cin>>choice;
//
if (choice < 1 || choice > 4)
cout<<choice<<" is an invalid choice. Program ending.";
//
else
{
//
cout<<endl;
//
cout<<"Enter the number of ounces ordered: ";
//
cin>>ounces;
//
// validate the amount ordered before proceeding
if (ounces < 1)
{
//
cout<<ounces<<" is an invalid amount of coffee. Program ending."<<endl;
//
return 0;
}
//
// this section finds the number of cups needed depending upon the ounces purchased
if (ounces <= 3)
num_cups_shot = ounces;
//
else
{
//
num_cups_reg = ounces/REGULAR_SIZE;
//
if (ounces%REGULAR_SIZE != 0)
num_cups_reg++;
//
}
// convert the order number to order name and store for future use
switch(choice)
{
//
case 1:
//
order = "Plain Coffee";
//
base_price = PLAIN_PER_OUNCE*ounces;
//
tax = base_price*SALES_TAX_RATE;
//
total = base_price + tax;
//
break;
//
case 2:
//
order = "Latte";
//
base_price = LATTE_PER_OUNCE*ounces;
//
tax = base_price*SALES_TAX_RATE;
//
total = base_price + tax;
//
break;
//
case 3:
//
order = "Macchiato";
//
// calculate total coffee cost
base_price = MAC_PER_OUNCE*ounces;
//
// find out tax
tax = base_price*SALES_TAX_RATE;
//
// calculate total
total = base_price + tax;
//
break;
//
case 4:
//
order = "Frappuccino";
//
base_price = FRAP_PER_OUNCE*ounces;
//
tax = base_price*SALES_TAX_RATE;
//
total = base_price + tax;
//
break;
//
}
//
// ask for customer name if the amount of coffee ordered is valid
cout<<"Enter the name of the customer: ";
//
// following two lines are needed to accept a string containing white space as input
cin.ignore();
//
getline(cin, customer_name);
//
cout<<endl;
//
// print the order summary and bill
//cout<<customer_name<<endl;
//
cout<<customer_name<<endl;
//
cout<<"Order: "<<order<<" "<<ounces<<" oz"<<endl;
//
// the setprecision and fixed flags are used to determine the number of fractional places to be displayed after decimal
cout<<"Price of Coffee: "<<"$"<<setprecision(2)<<fixed<<base_price<<endl;
//
cout<<"Sales Tax: "<<"$"<<tax<<endl;
//
cout<<"Total Amount Owed: "<<"$"<<total<<endl;
//
// display cup size information
cout<<endl;
//
cout<<"Cups Size Number Needed"<<endl;
//
cout<<"-------- ------------"<<endl;
//
cout<<"Verti "<<num_cups_verti<<endl;
//
cout<<"Grande "<<num_cups_grande<<endl;
//
cout<<"Regular "<<num_cups_reg<<endl;
//
cout<<"Shot "<<num_cups_shot<<endl;
//
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.