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: