asked 54.5k views
3 votes
C++ question: Jason opened a coffee shop selling coffee, cheese cakes, and coffee beans. Coffee is sold at the shop in two sizes: small (9 oz, $1.5) and large (12 oz, $1.9). Cheese cakes cost $3 per slice. Coffee beans are sold with $0.6 per oz. Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following: Choose among coffee, cakes, or beans to purchase. Buy coffee in any size and in any number of cups. Buy cheese cakes in any number of slices. Buy coffee beans in any amount. At any time show the total number of cups of each size sold, total number of slices of cakes sold, and total amount of coffee beans sold. At any time show the total amount of coffee sold. At any time show the total money made. Your program should consist of at least the following functions: a function to show the user how to use the program, a function to sell coffee, a function to sell cakes, a function to sell coffee beans, a function to show the number of cups of each size of coffee, the number of slices of cheese cakes, and the amount of coffee beans sold, a function to show the total amount of coffee sold, a function to show the total money made. Your program should not use any global variables. Special values such as coffee cup sizes and cost of a coffee cup must be declared as named constants.

asked
User Gnome
by
8.2k points

1 Answer

5 votes

Answer:

#include <iostream>

#include <iomanip>

#include <string>

// Constants

const double SMALL_COFFEE_SIZE = 9.0;

const double SMALL_COFFEE_PRICE = 1.5;

const double LARGE_COFFEE_SIZE = 12.0;

const double LARGE_COFFEE_PRICE = 1.9;

const double CHEESECAKE_PRICE = 3.0;

const double COFFEE_BEANS_PRICE = 0.6;

// Global variables

int smallCupsSold = 0;

int largeCupsSold = 0;

int slicesSold = 0;

double beansSold = 0.0;

double totalCoffeeSales = 0.0;

double totalRevenue = 0.0;

// Function prototypes

void showInstructions();

void sellCoffee();

void sellCheesecake();

void sellBeans();

void showInventory();

void showSales();

void showRevenue();

int main()

{

std::string choice;

showInstructions();

while (true)

{

std::cout << "\\Enter choice (C for coffee, K for cheesecake, B for beans, Q to quit): ";

std::cin >> choice;

if (choice == "C" || choice == "c")

{

sellCoffee();

}

else if (choice == "K" || choice == "k")

{

sellCheesecake();

}

else if (choice == "B" || choice == "b")

{

sellBeans();

}

else if (choice == "Q" || choice == "q")

{

break;

}

else

{

std::cout << "\\Invalid choice. Please try again.\\";

}

}

showInventory();

showSales();

showRevenue();

return 0;

}

// Function to show instructions

void showInstructions()

{

std::cout << "Welcome to Jason's coffee shop!\\";

std::cout << "We sell coffee, cheesecake, and coffee beans.\\";

std::cout << "Coffee is sold in two sizes: small (9 oz, $1.5) and large (12 oz, $1.9).\\";

std::cout << "Cheesecake costs $3 per slice.\\";

std::cout << "Coffee beans are sold at $0.6 per oz.\\";

std::cout << "Please choose from the following options:\\";

}

// Function to sell coffee

void sellCoffee()

{

std::string size;

int quantity;

double price = 0.0;

double sizeInOunces = 0.0;

std::cout << "\\Coffee sizes: S for small, L for large.\\";

std::cout << "Enter size: ";

std::cin >> size;

if (size == "S" || size == "s")

{

sizeInOunces = SMALL_COFFEE_SIZE;

price = SMALL_COFFEE_PRICE;

smallCupsSold++;

}

else if (size == "L" || size == "l")

{

sizeInOunces = LARGE_COFFEE_SIZE;

price = LARGE_COFFEE_PRICE;

largeCupsSold++;

}

else

{

std::cout << "\\Invalid size. Please try again.\\";

return;

}

std::cout << "Enter quantity: ";

std::cin >> quantity;

double totalSize = quantity * sizeInOunces;

double totalPrice = quantity * price;

std::cout << "\\Sold " << quantity << " cups of " << size << " coffee for a total of $" << std::fixed << std::setprecision(2) << totalPrice << ".\\";

totalCoffeeSales += totalSize;

totalRevenue += totalPrice;

}

// Function to sell cheesecake

void sellCheesecake()

{

int quantity;std::cout << "\\Enter quantity: ";

std::cin >> quantity;

double totalPrice = quantity * CHEESECAKE_PRICE;

std::cout << "\\Sold " << quantity << " slices of cheesecake for a total of $" << std::fixed << std::setprecision(2) << totalPrice << ".\\";

slicesSold += quantity;

totalRevenue += totalPrice;

}

// Function to sell cheesecake

void sellCheesecake()

{

int quantity;

std::cout << "\\Enter quantity: ";

std::cin >> quantity;

double totalPrice = quantity * CHEESECAKE_PRICE;

std::cout << "\\Sold " << quantity << " slices of cheesecake for a total of $" << std::fixed << std::setprecision(2) << totalPrice << ".\\";

slicesSold += quantity;

totalRevenue += totalPrice;

}

// Function to sell coffee beans

void sellBeans()

{

double quantity;

std::cout << "\\Enter quantity in ounces: ";

std::cin >> quantity;

double totalPrice = quantity * COFFEE_BEANS_PRICE;

std::cout << "\\Sold " << quantity << " ounces of coffee beans for a total of $" << std::fixed << std::setprecision(2) << totalPrice << ".\\";

beansSold += quantity;

totalRevenue += totalPrice;

}

// Function to show inventory

void showInventory()

{

std::cout << "\\Inventory:\\";

std::cout << "Small coffee cups sold: " << smallCupsSold << "\\";

std::cout << "Large coffee cups sold: " << largeCupsSold << "\\";

std::cout << "Cheesecake slices sold: " << slicesSold << "\\";

std::cout << "Coffee beans sold (in ounces): " << std::fixed << std::setprecision(2) << beansSold << "\\";

}

// Function to show total coffee sales

void showSales()

{

std::cout << "\\Total coffee sold (in ounces): " << std::fixed << std::setprecision(2) << totalCoffeeSales << "\\";

}

// Function to show total revenue

void showRevenue()

{

std::cout << "\\Total revenue: $" << std::fixed << std::setprecision(2) << totalRevenue << "\\";

}

Step-by-step explanation:

answered
User CMash
by
8.0k points

No related questions found

Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.