Jamal opened a coffee shop at WakeTech and sells coffee in three sizes: small (9
ID: 3813218 • Letter: J
Question
Jamal opened a coffee shop at WakeTech 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 provide the following menu options:
1: Enter 1 to order coffee.
2: Enter 2 to check the total money made up to this time.
3: Enter 3 to check the number of cups of coffee of each size sold.
4: Enter 4 to print all the data.
9: Enter 9 to exit the program.
Your program should consist of at least the following functions:
A function to display the user how to use the program. ( void menu() ) -- Displays menu only and does not prompt user. (2 pts)
Choice 1: A function to sell the coffee.-- This function does most of the calculations (20 pts)
void sellCoffee(int& sCupCount, int &mCupCount, int& lCupCount, int& totalCoffeeSold, double& tMoneyMade)
sCupCount = Number of small cup size
mCupCount = Number of medium cup size
lCupCount = Number of large cup size
totalCoffeeSold = Total number of ounces sold
tMoneyMade = Total money made
This function should prompt user for information
Choice 2: A function to display the total money made. ( voidshowMoneyMade(double m) ) -- where m = total money made. (5 pts)
Choice 3: A function to display the number of cups of each size sold. ( void showCupCount(int s, int m, int l) ) -- where: s = small, m = medium, l = large (5 pts)
Choice 4: No function is required to display all the data (i.e. number of cups of each size sold and total money made) (5 pts)
Program successfully runs and provides an option to Exit (Choice 9). (3 pts)
Your program should not use any global variables and special values
Explanation / Answer
Hey I fixed up your program for you and added all of the features that were required.
I made it way more complicated than it had to be so sorry about that haha.
Main.cpp
#include "CoffeeShop.h"
int main()
{
CoffeeShop Shop;
Shop.Menu();
return 0;
}
Code For Header File. I made it for the purpose of code reusability or you can say that for implementing less line of codes
and will guide everyone to use such methods these are for good practices.
CoffeeShop.h
#pragma once
#include <iostream>
#include <iomanip>
#include <utility>
#include <sstream>
#include <string>
class CoffeeShop
{
public:
void Menu();
void BuyCoffee(int type, int amount);
void ShowCoffeeSold();
void ShowProfit();
std::pair<int, int> ParseString(const std::string &TypeAmount);
private:
double profit = 0;
const double smallPrice = 1.75;
const double mediumPrice = 1.90;
const double largePrice = 2.00;
int smallsSold = 0;
int mediumsSold = 0;
int largesSold = 0;
};
This is the main program where you have all the given business logic of the program and hope that i have met all the requirements
of your program.
CoffeeShop.cpp
#include "CoffeeShop.h"
void CoffeeShop::Menu()
{
std::string coffeeInput;
while(coffeeInput != "exit")
{
std::cout << "Jamal's Coffee Shop ";
std::cout << "Menu ";
std::cout << "# Item Price ";
std::cout << "1 Small Coffee $1.75 ";
std::cout << "2 Medium Coffee $1.90 ";
std::cout << "3 Large Coffee $2.00 ";
std::cout << "Enter coffee # that you wish to purchase followed by a ',' and the amount or enter '4' to view total cups of each size sold '5' to view profit: ";
std::getline(std::cin, coffeeInput);
std::pair<int, int> parsedString = ParseString(coffeeInput);
system("cls");
switch(parsedString.first)
{
case 1:
case 2:
case 3:
system("cls");
BuyCoffee(parsedString.first, parsedString.second);
break;
case 4:
system("cls");
ShowCoffeeSold();
break;
case 5:
system("cls");
ShowProfit();
break;
}
}
}
void CoffeeShop::BuyCoffee(int type, int amount)
{
switch(type)
{
case 1:
profit += smallPrice * amount;
smallsSold += amount;
std::cout << amount << " small coffie(s) bought for $" << smallPrice * amount;
break;
case 2:
profit += mediumPrice * amount;
mediumsSold += amount;
std::cout << amount << " medium coffie(s) bought for $" << mediumPrice * amount;
break;
case 3:
profit += largePrice * amount;
largesSold += amount;
std::cout << amount << " large coffie(s) bought for $" << largePrice * amount;
break;
}
std::cout << " Press enter to continue.";
std::cin.ignore();
system("cls");
}
void CoffeeShop::ShowCoffeeSold()
{
std::cout << "Coffee Sold ";
std::cout << "Type Amount ";
std::cout << "Small " << smallsSold << " ";
std::cout << "Medium " << mediumsSold << " ";
std::cout << "Large " << largesSold << " ";
std::cout << "Total " << smallsSold + mediumsSold + largesSold << " ";
std::cout << " Press enter to continue.";
std::cin.ignore();
system("cls");
}
void CoffeeShop::ShowProfit()
{
std::cout << "Profit ";
std::cout << "Profit some small coffies: " << smallsSold * smallPrice << " ";
std::cout << "Profit some medium coffies: " << mediumsSold * mediumPrice << " ";
std::cout << "Profit some large coffies: " << largesSold * largePrice << " ";
std::cout << "Total profit: " << (smallsSold * smallPrice) + (mediumsSold * mediumPrice) + (largesSold * largePrice);
std::cout << " Press enter to continue.";
std::cin.ignore();
system("cls");
}
std::pair<int, int> CoffeeShop::ParseString(const std::string &TypeAmount)
{
std::istringstream iss(TypeAmount);
std::string tempType;
std::getline(iss, tempType, ',');
std::string tempAmount;
std::getline(iss, tempAmount);
int type;
std::istringstream(tempType) >> type;
int amount;
std::istringstream(tempAmount) >> amount;
return std::pair<int, int>(std::move(type), std::move(amount));
}
I hope it helps!
EDIT:
If you're not running on windows, remove all of the system("cls") and just add some new lines if you want.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.