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

a c++ program that does this but I need it in a very simple format using only io

ID: 3824725 • Letter: A

Question

a c++ program that does this but I need it in a very simple format using only iostream int and also cstring if necessary

You 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 $2.75, one medium cup is $2.90, and one large cup is $3.00.

Task

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.

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 show the number of cups of each size sold,

• a function to show the total amount of coffee sold, and a function to show the total money made.

Your program should not use any global variables and special values such as coffee cup sizes and cost of a coffee cup must be declared as named constants

Explanation / Answer

Here is the C++ program for the above scenario:

Main.cpp

#include "CoffeeShop.h"

int main()

{

CoffeeShop Shop;

Shop.Menu();

return 0;

}

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 = 5.00;

int smallsSold = 0;

int mediumsSold = 0;

int largesSold = 0;

};

CoffeeShop.cpp

#include "CoffeeShop.h"

void CoffeeShop::Menu()

{

std::string coffeeInput;

while(coffeeInput != "exit")

{

std::cout << "Jason'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 $5.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));

}

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