anonymous
2008-12-09 18:54:40 UTC
This is what i need to do:
I need to create a class (called MachineManager) that simulates a soft drink machine. The class should use a struct that stores
the following information:
Drink name
Drink price
Number of drinks in machine
The class should have an array of five of these struct.
The elements should be initialized (using a default constructor) to handle the
initialization with the following data:
--------------------------------------------------------------------------------
Drink Name < Cost <<< Number in Machine
Cola < .75 <<<< 20
Root beer < .75 <<<<< 20
Orange Soda < .75 <<<<20
Grape Soda < .75 <<<<20
Bottled water 1.00 <<<20
--------------------------------------------------------------------------------
#include
#include
#include
using namespace std;
struct Drinks
{
string Name;
double Price;
int Quantity;
};
class MachineManager
{
private:
void inputMoney();
void dailyReport();
public:
void displayChoices();
void buyDrink (int);
};
void displayChoices ()
{
cout << "**** Machine Beverage Choices ****" << endl;
cout << " 1) Cola $ 0.75"<
cout << " Please enter the number of your drink choice" << endl;
cin >> int choice;
buyDrink (int);
}
void buyDrink (choice)
{
inputMoney (choice);
}
void inputMoney (choice)
{
if (Quantity = 0)
cout << "Sold out. Please remove your change." << endl;
cout << "Please insert sufficient money for your beverage choice" << endl;
cout << "Enter 0 if you do not want to purchase the drink" << endl;
cin >> Price;
if (int = 6)
cout << "Please remove your change" << endl;
if (int <= 4)
{if (Price < 0.75)
cout << "Incorrect amount of money, please remove your money from the coin return slot" << endl;
else
double change = Price - 0.75;
{if (change = 0)
cout << "Enjoy your drink" << endl;
else
cout << "Your change is" << change << endl;
cout << "Enjoy your drink" << endl;}}
if (int = 5)
{ if (Price < 1)
cout << "Incorrect amount of money, please remove your change from the coin slot" << endl;
else
{double change = Price - 1.0;
if (change = 0)
cout << "Enjoy your drink" << endl;
else
cout << "Your change is" << change << endl;
cout << "Enjoy your drink" << endl;}
}
void dailyReport ()
{
Drinks drinkinfo[4];
Drinks[0].Name = Cola, Price = 0.75, Quantity = 20;
Drinks[1].Name = RootBeer, Price = 0.75, Quantity = 20;
Drinks[2].Name = OrangeSoda, Price = 0.75, Quantity = 20;
Drinks[3].Name = GrapeSoda, Price = 0.75, Quantity = 20;
Drinks[4].Name = BottledWater, Pirce = 1.00, Quantity = 20;
if (choice = 1, choice++,)
int getChoice(int);
int main()
{
MachineManager machine; // Create a MachineManager object
int quitChoice = 6;
int choice; // Patron menu choice
do
{ machine.displayChoices(); // Lists choices and prices
cout << setw(5) << quitChoice << ") Exit \n\n" ;
choice = getChoice(quitChoice);
if (choice != quitChoice)
machine.buyDrink(choice);
} while (choice != quitChoice);
return 0;
}
int getChoice (int quitChoice)
{
int choice;
cin >> choice;
while (choice < 1 || choice > quitChoice)
{
cout << "Valid choices are 1 - " << quitChoice
<< ". Please re-enter choice: ";
cin >> choice;
}
return choice;
}