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

17. Drink Machine Simulator Create a class that simulates and manages a soft dri

ID: 3730806 • Letter: 1

Question

17. Drink Machine Simulator Create a class that simulates and manages a soft drink machine. Information on each drink type should be stored in a structure that has data members to hold the drink name, the drink price, and the number of drinks of that type currently in the machine. The class should have an array of five of these structures, initialized with the following data. Drink Name Cola Root beer Orange soda Grape soda Bottled water Number in Machine Cost 1.00 1.00 1.00 1.00 1.50 20 The class should have two public member functions, displayChoices (which displays a menu of drink names and prices) and buyDrink (which handles a sale). The class should also have at least two private member functions, inputMoney, which is called by buyDrink to accept, validate, and return (to buyDrink) the amount of money input, and dailyReport, which is called by the destructor to report how many of each drink type remain in the machine at the end of the day and how much money was collected You may want to use additional functions to make the program more modular. The client program that uses the class should have a main processing loop that calls the displayChoices class member function and allows the patron to either pick a drink or quit the program. If the patron selects a drink, the buyDrink class member function is called to handle the actual sale. This function should be passed the patron's drink choice. Here is what the buyDrink function should do: . Call the 1nputMoney function, passing it the patron's drink choice. If the patron no longer wishes to make the purchase, return all input moncy . If the machine is out of the requested soda, display an appropriate sold out" . If the machinc has the soda and cnough money was entered, complete the sale by message and return all input money updating the quantity on hand and money collected information, calculating any change due to be returned to the patron, and delivering the soda. This last action can be simulated by printing an appropriate "here is your beverage" message. In C++

Explanation / Answer

Below is the code for the soft drink dispencer machine.

#include <iostream>

using namespace std;

struct Drink {
    string name;
    float cost;
    int totQty;
};

class softDrinkMachine {

    Drink drink[5];
    float totAmt;

public:
    softDrinkMachine()
    {
        drink[0].name = "cola";
        drink[0].cost = 1.00;
        drink[0].totQty = 20;

        drink[1].name = "Root beer";
        drink[1].cost = 1.00;
        drink[1].totQty = 20;

        drink[2].name = "Orange soda";
        drink[2].cost = 1.00;
        drink[2].totQty = 20;

        drink[3].name = "Grape soda";
        drink[3].cost = 1.00;
        drink[3].totQty = 20;

        drink[4].name = "Bottled water";
        drink[4].cost = 1.50;
        drink[4].totQty = 20;

        totAmt = 0;
    }
    ~softDrinkMachine()
    {
        dailyReport();
    }

    void displayChoices()
    {
        cout << "Drink Names Prices" << endl;
        cout << "----------- ------" << endl;
        cout << "1: Cola 1.00" << endl;
        cout << "2: Root beer 1.00" << endl;
        cout << "3: Orange soda 1.00" << endl;
        cout << "4: Grape soda 1.00" << endl;
        cout << "5: Bottled water 1.50" << endl;
        cout << "6: Exit" << endl;
        cout << "Enter your choice : ";
    }
    void buyDrink(int choice)
    {
        if (6 == choice) {
            dailyReport();
            exit(1);
        }
        inputMoney(choice);
    }

private:
    void inputMoney(int choice)
    {
        float amt;
        if (0 == drink[choice - 1].totQty) {
            cout << "Sold Out" << endl;
            return;
        }
        cout << "Enter the input amount : ";
        cin >> amt;
        amt = amt - drink[choice - 1].cost;
        drink[choice - 1].totQty--;

        totAmt += drink[choice - 1].cost;
        cout << "Here is your beverage" << endl;
        if (amt > 0.0)
            cout << "Balance amount : " << amt << endl;
    }
    void dailyReport()
    {
        cout << "Drink Names Available Qty" << endl;
        cout << "----------- -------------" << endl;
        cout << "Cola " << drink[0].totQty << endl;
        cout << "Root beer " << drink[1].totQty << endl;
        cout << "Orange soda " << drink[2].totQty << endl;
        cout << "Grape soda " << drink[3].totQty << endl;
        cout << "Bottled water " << drink[4].totQty << endl;
        cout << "Total Sales Amount today : " << totAmt << endl;
    }
};

int main()
{
    int choice;
    softDrinkMachine sdm;
    while (1) {
        sdm.displayChoices();
        cin >> choice;
        sdm.buyDrink(choice);
    }
    return 0;
}

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