Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have been hired by a local smoothie shop to a program that will calculate the cost of a smoothie order. The shop sells four

You have been hired by a local smoothie shop to a program that will calculate the cost of a smoothie order. The shop sells four types of smoothies in three different sizes: Small (20 oz), Medium (32 oz) and Large (40 oz). Your program should use a menu for the type of smoothie and a second menu for the smoothie size. Calculate the total cost of the order including tax and display a bill for the smoothie. See the Sample Output. The sales tax rate is 4.5%. Usenamed constantsto hold the cost per ounce of each of the products and the sales tax rate. Use the constants in your calculations and wherever else they are appropriate in your program.

Product Cost per Ounce Banana $0.62 Strawberry $0.60

Mango $0.48

Blueberry $0.57

Project 3 is a continuation of Projects 1 and 2. You will modify your code from Project 2 to make the program modular for this part of the project.

Instead of having one long main function that contains all the statements necessary to solve the problem given in previous projects, you must several smaller functions that each solve a specific part of the problem. These small functions should then be executed correctly to implement a complete solution.

The named constants you used in previous projects should now be made global so you won't have to pass those values to any function.

In addition to the main function, your code must include the specified functions. These functions must be exactly as specified to avoid a major error penalty (1 major error per incorrect function).

Make sure your program uses the values returned from your functions. Any functions that need input to perform a task will have to accept arguments.Global variables are prohibited.

Steps:

  1. Make all of your named constantsglobal.
  2. Define prototypes and define the following functions:

Function 1 - displayStartMenu

A void function that only displays the first menu. See Sample Outputfor format.

Function 2 - determineCostPerOz

A double returning function that accepts the user's menu choice for type of smoothie and returns the price per ounce.

Function 3 - determineNumberOunces

An integer returning function that accepts the user's menu choice for size of smoothie and returns the number of ounces.

Function 4- calcSmoothieSubtotal

A double returning function that accepts the price per ounce and the number of ounces purchased and returns the price of the smoothie.

Function 5- calcSalesTax

A double returning function that ONLY accepts the price of the smoothie and returns the sales tax.

Function 6- calcCostBill

A double method that accepts the price of the smoothie and the sales tax and returns the total amount owed.

Now adds new function it and run it like a professional

sample

#include #include #include #include using namespace std;

// main function int main() { // input srand(time(0)); // seed random number // variables int smoothieType; // variable to hold the menu choice of the type of smoothie int size; // variable to hold the menu choice of the size of smoothie string name; // variable to hold the customer name double subtotal; // variable to hold the calculated subtotal of the smoothie order double salesTax; // variable to hold the calculated sales tax of the smoothie order double total; // variable to hold the calculated total of the order int menuChoice; // variable to hold the main menu choice int numOrders; // variable to hold the number of orders to be generated // constants const double BANANA = 0.62; // banana smoothies cost $0.62 per ounce const double STRAWBERRY = 0.60; // strawberry smoothies cost $0.60 per ounce const double MANGO = 0.48; // mango smoothies cost $0.48 per ounce const double BLUEBERRY = 0.57; // blueberry smoothies cost $0.57 per ounce const double SALES_TAX = 0.045; // 4.5% sales tax rate // display the title cout << "Welcome to the Smoothest Smoothie Shop "; do { // display the main menu cout << "Main Menu "; cout << "\t1 - Process a Single Order "; cout << "\t2 - Process Multiple Orders "; cout << "\t3 - Quit "; cout << "Enter choice of action: "; cin >> menuChoice; if(menuChoice == 1) { // process a single order // display the smoothie type menu cout << " Choose your smoothie flavor: "; cout << "\t1 - Banana ($0.62 / oz) "; cout << "\t2 - Strawberry ($0.60 / oz) "; cout << "\t3 - Mango ($0.48 / oz) "; cout << "\t4 - Blueberry ($0.57 / oz) "; cout << "Enter choice of smoothie: "; cin >> smoothieType; // validate the input of the smoothie type while(smoothieType < 1 or smoothieType > 4) { // display an error and get another input cout << " ERROR: INVALID MENU CHOICE. TRY AGAIN. "; cout << " Choose your smoothie flavor: "; cout << "\t1 - Banana ($0.62 / oz) "; cout << "\t2 - Strawberry ($0.60 / oz) "; cout << "\t3 - Mango ($0.48 / oz) "; cout << "\t4 - Blueberry ($0.57 / oz) "; cout << "Enter choice of smoothie: "; cin >> smoothieType; } // display the size menu cout << " Choose your smoothie size: "; cout << "\t1 - Small (20 oz) "; cout << "\t2 - Medium (32 oz) "; cout << "\t3 - Large (40 oz) "; cout << "Enter choice of size: "; cin >> size; // validate the input of the smoothie size while(size < 1 or size > 3) { // display an error and get another input cout << " ERROR: INVALID MENU CHOICE. TRY AGAIN. "; cout << " Choose your smoothie size: "; cout << "\t1 - Small (20 oz) "; cout << "\t2 - Medium (32 oz) "; cout << "\t3 - Large (40 oz) "; cout << "Enter choice of size: "; cin >> size; } // clear the buffer cin.ignore(); // get the input of the customer's name cout << " Enter the name of the customer: "; getline(cin, name); // processing if(smoothieType == 1) { // banana smoothie if(size == 1) subtotal = BANANA * 20.0; // small (20 oz) else if(size == 2) subtotal = BANANA * 32.0; // medium (32 oz) else subtotal = BANANA * 40.0; // large (40 oz) } else if(smoothieType == 2) { // strawberry smoothie if(size == 1) subtotal = STRAWBERRY * 20.0; // small (20 oz) else if(size == 2) subtotal = STRAWBERRY * 32.0; // medium (32 oz) else subtotal = STRAWBERRY * 40.0; // large (40 oz) } else if(smoothieType == 3) { // mango smoothie if(size == 1) subtotal = MANGO * 20.0; // small (20 oz) else if(size == 2) subtotal = MANGO * 32.0; // medium (32 oz) else subtotal = MANGO * 40.0; // large (40 oz) } else { // blueberry smoothie if(size == 1) subtotal = BLUEBERRY * 20.0; // small (20 oz) else if(size == 2) subtotal = BLUEBERRY * 32.0; // medium (32 oz) else subtotal = BLUEBERRY * 40.0; // large (40 oz) } // calculate the sales tax salesTax = subtotal * SALES_TAX; // calculate the total total = subtotal + salesTax; // output // format to display 2 decimals cout << setprecision(2) << showpoint << fixed; cout << endl << name << endl; cout << "Subtotal: $" << subtotal << endl; cout << "Sales Tax: $" << salesTax << endl; cout << "Total: $" << total << endl << endl; } else if(menuChoice == 2) { // process multiple orders cout << " How many orders would you like to generate (min: 1 - max: 10): "; cin >> numOrders; while(numOrders < 1 or numOrders > 10) { // display an error and get another input cout << " ERROR: INVALID NUMBER OF ORDERS ENTERED. TRY AGAIN. "; cout << " How many orders would you like to generate (min: 1 - max: 10): "; cin >> numOrders; } // process the orders for(int order = 1; order <= numOrders; order++) { // generate a smoothie type smoothieType = 1 + rand() % 4; // generate a size size = 1 + rand() % 3; if(smoothieType == 1) { // banana smoothie if(size == 1) subtotal = BANANA * 20.0; // small (20 oz) else if(size == 2) subtotal = BANANA * 32.0; // medium (32 oz) else subtotal = BANANA * 40.0; // large (40 oz) } else if(smoothieType == 2) { // strawberry smoothie if(size == 1) subtotal = STRAWBERRY * 20.0; // small (20 oz) else if(size == 2) subtotal = STRAWBERRY * 32.0; // medium (32 oz) else subtotal = STRAWBERRY * 40.0; // large (40 oz) } else if(smoothieType == 3) { // mango smoothie if(size == 1) subtotal = MANGO * 20.0; // small (20 oz) else if(size == 2) subtotal = MANGO * 32.0; // medium (32 oz) else subtotal = MANGO * 40.0; // large (40 oz) } else { // blueberry smoothie if(size == 1) subtotal = BLUEBERRY * 20.0; // small (20 oz) else if(size == 2) subtotal = BLUEBERRY * 32.0; // medium (32 oz) else subtotal = BLUEBERRY * 40.0; // large (40 oz) } // calculate the sales tax salesTax = subtotal * SALES_TAX; // calculate the total total = subtotal + salesTax; // format to display 2 decimals cout << setprecision(2) << showpoint << fixed; cout << endl << "Order #" << order << endl; cout << "Subtotal: $" << subtotal << endl; cout << "Sales Tax: $" << salesTax << endl; cout << "Total: $" << total << endl << endl; } } else if(menuChoice == 3) { // quit the program cout << " Thank you for using the program. "; } else { // input validation cout << " ERROR: INVALID MENU CHOICE. TRY AGAIN. "; } }while(menuChoice != 3); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

Students also viewed these Programming questions

Question

=+e. Stock prices rise by 20 percent.

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago