Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Jason opened a coffee shop at the beach and sells coffee in three sizes: small (

ID: 3853412 • Letter: J

Question

Jason opened a coffee shop at the beach and sells coffee in three sizes: small (9oz), medium (12oz), and large (15oz). The cost of one small cup is $1.75, one medium cup is $1.90, and one large cup is $2.00. Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following:

Buy coffee in any size and in any number of cups.

At any time show the total number of cups of each size sold.

At any time show the total amount of coffee sold.

At any time show the total money made.

The buy coffee option allows the customer to select the number of cups in each of the sizes they want to order and display a receipt for that order. The other three options would be used by the owner to check on the status of the shop during the day.

Design a modular program to implement this program. Pay attention to the user interface. Try to minimize the number of times the user is required to touch the keyboard.

Turn in: structure chart, source code and output showing test results (screen shot or picture)

Checklist:

Structure chart included.

File name included as comment at top of source file

IPO chart included as comments following the file name

Variable names are meaningful

IPO charts for functions incorporated as comments before each function

Program compiles

Program prompts for input and validates as needed.

Program output is formatted neatly

Program produces correct results

Program is thoroughly tested with test output included

For this program, you need to use a menu-driven loop. There is an item in the Chapter 6 Content area, PowerPoint Slides and Notes folder that shows you how to do that. To keep the running total of the coffee purchased during the day, you would declare local variables in main to keep track of the number of cups in each size purchased through out the day. You would pass these variables by reference to a function which allows a customer to purchase coffee and then pass them by value to the manager's functions to see the totals throughout the day. Below is an example structure chart for this program. This structure chart includes the data flows showing what data is going into the functions and what data is coming out of the functions. Parameters labeled Input/Output are implemented as reference parameters. The prototypes you would use to implement this structure chart are also shown.

Some things to keep in mind:

Do not use global variables.

All communication between modules should be done through parameter lists.

Do not make all your parameters reference parameters. Parameters should be passed by value except when you need to return the values of multiple variables back to the calling function.

You do not need to include the data flows in your structure charts.

You do not need to implement this design, but your design must not use global variables and must pass parameters appropriately.

void showMainMenu();
// Displays main menu choices

Explanation / Answer

Here i s the code and output for the question. Post a comment in case of any issues, I shall respond. Please rate the answer if it helped. Thank you.

#include <iostream>

using namespace std;

//declare the quantity in ounce for different cup sizes

const int SMALL_QTY = 9;

const int MEDIUM_QTY = 12;

const int LARGE_QTY = 15;

//declare constants for price of different cup sizes

const double SMALL_COST = 1.75;

const double MEDIUM_COST = 1.9;

const double LARGE_COST = 2.0;

void showMainMenu();

// Displays main menu choices

void buyCoffee(int&, int&, int&);

// Allows customer to place a coffee order

// Program Input - number of small, medium, and large cups of coffee customer wants to order

// Input/Output Parameters - Total number of small, medium, and large cups (including this purchase) made so far

// Preconditions - the total number of small, medium, and large cups from past purchases is passed into the function.

// - the price per cup for each size has been declared as a global constant

// Postconditions - the function displays a receipt for the current purchase,

//the total number of small, medium, and large cups is updated to include the current purchase

void showCoffeeMenu();

//Displays the coffee menu

void showReceipt(int, int, int);

// Displays a receipt of the current transaction, showing the number of cups in each size sold,

// the subtotal amounts for each size, and the total amount due.

// Input Parameters - number of small, medium, and large cups purchased in this transaction

// Postconditions - the receipt is displayed

void cupsSold(int, int, int);

// Displays the total number of cups of coffee in each size that has been sold so far

// Input parameters - total number of small, medium, and large cups sold so far

// Postconditions - program output to display of total number of small, medium, and large cups sold so far

void coffeeSold(int, int, int);

// Calculates and displays the total amount of coffeee sold (in oz.) so far

// Input parameters - the total number of small, medium, and large cups sold so far

// Preconditions - the number of ounces per cup for each size has been declared as a global constant

// Postconditions - the total number of ounces is calculated and displayed as program output.

void totalAmount(int, int, int);

// Calculates and displays the total amount of money that has been made so far

// Input parameters - the total number of small, medium, and large cups sold so far

// Preconditions - the price per cup for each size has been declared as a global constant

// Postconditions - the total amount of money made is calculated and displayed as program output.

int main()

{

showMainMenu();

}

void showMainMenu()

{

int choice = 0;

int small = 0 , medium = 0, large = 0;

  

while(choice != 5)

{

cout << "1. Buy coffee" << endl;

cout << "2. Show total number of cups " << endl;

cout << "3. Show total amount of coffee" << endl;

cout << "4. Show total money" << endl;

cout << "5. Exit" << endl;

cout << "Enter your choice: " ;

cin >> choice;

switch(choice)

{

case 1:

buyCoffee(small, medium, large);

break;

case 2:

cupsSold(small, medium, large);

break;

case 3:

coffeeSold(small, medium, large);

break;

case 4:

totalAmount(small, medium, large);

break;

case 5:

break;

default:

cout << "Invalid menu choice" << endl;

}

  

}

  

}

void buyCoffee(int& small, int& medium, int& large)

{

int choice = 0, qtys = 0, qtym = 0, qtyl = 0, qty = 0;

string ans = "y";

while(ans == "y")

{

choice = 0;

qty = 0;

  

while(choice <1 || choice > 3)

{

showCoffeeMenu();

cout << "Enter your choice: " ;

cin >> choice;

}

  

  

while(qty < 1)

{

cout << "How many cups? " ;

cin >> qty;

}

  

if(choice == 1)

{

small += qty;

qtys += qty;

}

else if(choice == 2)

{

medium += qty;

qtym += qty;

}

else

{

  

large += qty;

qtyl += qty;

}

  

cout << "Do you want to order more? y/n : ";

cin >> ans;

}

  

showReceipt(qtys, qtym, qtyl);

  

}

void showCoffeeMenu()

{

cout << " 1. Buy small cup (" << SMALL_QTY << "oz)" << endl;

cout << "2. Buy medium cup (" << MEDIUM_QTY << "oz)" << endl;

cout << "3. Buy large cup (" << LARGE_QTY << "oz)" << endl;

}

void showReceipt(int qtys, int qtym, int qtyl)

{

double total = 0;

cout << "Order details:-" << endl;

if(qtys != 0)

{

cout << "Small cups: " << qtys << " @ $" << SMALL_COST << " = $" << (SMALL_COST * qtys) << endl;

total += (SMALL_COST * qtys);

}

  

if(qtym != 0)

{

cout << "Medium cups: " << qtym << " @ $" << MEDIUM_COST << " = $" << (MEDIUM_COST * qtym) << endl;

total += (MEDIUM_COST * qtym);

}

if(qtyl != 0)

{

cout << "Large cups: " << qtyl << " @ $" << LARGE_COST << " = $" << (LARGE_COST * qtyl) << endl;

total += (LARGE_COST * qtyl);

}

  

cout <<" Total amount = $" << total << endl << endl;

  

}

void cupsSold(int small, int medium, int large)

{

cout << "The number of cups sold is " << endl;

cout << "Small: " << small << " cups" << endl;

cout << "Medium: " << medium << " cups" << endl;

cout << "Large: " << large << " cups" << endl << endl;

  

}

void coffeeSold(int small, int medium, int large)

{

double total = small * SMALL_QTY + medium * MEDIUM_QTY + large * LARGE_QTY;

cout << "Total amount of coffe sold is " << total << "ounces" << endl << endl;

}

void totalAmount(int small, int medium, int large)

{

double total = small * SMALL_COST + medium * MEDIUM_COST + large * LARGE_COST;

cout << "Total amount of money made is $" << total << endl << endl;

}


output

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 1

1. Buy small cup (9oz)
2. Buy medium cup (12oz)
3. Buy large cup (15oz)
Enter your choice: 1
How many cups? 2
Do you want to order more? y/n : y

1. Buy small cup (9oz)
2. Buy medium cup (12oz)
3. Buy large cup (15oz)
Enter your choice: 2
How many cups? 1
Do you want to order more? y/n : n
Order details:-
Small cups: 2 @ $1.75 = $3.5
Medium cups: 1 @ $1.9 = $1.9

Total amount = $5.4

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 1

1. Buy small cup (9oz)
2. Buy medium cup (12oz)
3. Buy large cup (15oz)
Enter your choice: 3
How many cups? 1
Do you want to order more? y/n : n
Order details:-
Large cups: 1 @ $2 = $2

Total amount = $2

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 2
The number of cups sold is
Small: 2 cups
Medium: 1 cups
Large: 1 cups

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 3
Total amount of coffe sold is 45ounces

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 4
Total amount of money made is $7.4

1. Buy coffee
2. Show total number of cups
3. Show total amount of coffee
4. Show total money
5. Exit
Enter your choice: 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote