Drink Machine Simulator

Create a class that simulates and manages a soft drink machine

Page 1 of 1

2 Replies - 4860 Views - Last Post: 19 October 2009 - 03:03 PM Rate Topic: -----

#1 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Drink Machine Simulator

Posted 18 October 2009 - 10:53 PM

Create a class that simulates and manages a soft drink machine. The class should use a structure that stores the following information:

Drink name
Drink price
Number of drinks in machine

The class should have an array of five of these structures. The elements should be initialized 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

Hint: Use constructors to handle the initialization.

The class should have two public member functions, displayChoices (which display 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 which 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 called to handle the actual sale. This function should be passed the patron's drink choice Here is what the buyDrink function should do:

1) Call the inputMoney function, passing it the patron's dirnk choice.
2) If the patron no longer wishes to make the purchase, return all input money.
3) if the machine is out of the requested soda, display an appropriate "sold out" message and return all input money.
4) If the machine has the soda and enough money was entered, complete the sale by updating the quantity on hand an dmoney collected information, calculating any change due to be returned to the patron, and delevering the soda. This last action can be simulated by printing an appropriate "here is your beverage" message.

Input Validation: only accept valid menu choices. Do not deliver a beverage if the money inserted is less than the price of the selected drink



 
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;


	struct drink
	{
		  string drinkName;
		  double drinkPrice;
		  int drinks;
	 };
	 
	class drinkManager
	{
	private:
		   void inputMoney();
		   void dailyReport();
	public:
		   void displayChoices();
		   void buyDrink(int);
		   };	   
		   
		   
		   
   void displayChoices()
   {
 int choice = 0;
	cout << "*Menu of drinks and prices*" << endl;
	cout << " Drink Name			Cost" << endl;
	cout << "(1)Cola				 .75" << endl;
	cout << "(2)Root Beer			.75" << endl;
	cout << "(3)Orange Soda		  .75" << endl;
	cout << "(4)Grape Soda		   .75" << endl;
	cout << "(5)Bottled Water		.75" << endl;
	cout << "(6)EXIT					" << endl;
	cin >> choice;
   // buyDrink(int)
	};
	
   // void buyDrink(choice)
	//{
	  //   inputMoney(choice);
	//}
	
   int inputMoney(choice)
   {
		
		if(qty = 0)
		{
		
		
		
			cout << "Sorry, currently sold out." << endl;
			
			cout << "Please remove change" << endl;
			cout << "Please enter money or (6) to EXIT" << endl;
			cin >> price;
			
			if (int = 6)
			{
			cout << "Please remove change" << endl;
			}
			
			if (int = 5) 
			{
			   if (price < 1)
			   {
				 cout << "not enough change, please remove change from slot" << endl;
				 }
			   else 
			   double change = price - 1;
			   if (change = 0)
			   {
				 cout << "Thank you, enjoy" << endl;
			   else
				 cout << "Change: " change << endl;
				 cout << "Thank you, enjoy" << endl;
				 }
			}
			if (int <= 4)
			{
			   if (price < .75)
			   {
				 cout << "not enough change, please remove change from slot" << endl;
			   }
			   else
			   double change = price - .75;
			   if (change = 0)
			   {
				 cout << "Thank you, enjoy" << endl;
				 }
			   else
			   {
				 cout << "Change: " change << endl;
				 cout << "Thank you, enjoy" << endl;
				 }
			}
			
			void dailyReport
			{
			
				 drink report[4];
					drink[0].Name = Cola, price = 0.75; qty = 20;
					drink[1].Name = Root Beer, price = 0.75; qty = 20;
					drink[2].Name = Orange Soda, price = 0.75; qty = 20;
					drink[3].Name = Grape Soda, price = 0.75; qty = 20;
					drink[4].Name = Bottled Water, price = 1; qty = 20;
					cout << drink[0].Name
					}
		
   );

	 int main()
	 int choice;
	 int quit = 6;
	 
	 
	 
 drinkManager manager;
 manager.displayChoices();

{
   

	system ("PAUSE");
	return 0;
}	





Not finished yet but really really stumped please tell me if there is an easier way to do this :/

This post has been edited by BigJohnson: 18 October 2009 - 11:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Drink Machine Simulator

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: Drink Machine Simulator

Posted 19 October 2009 - 05:37 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Re: Drink Machine Simulator

Posted 19 October 2009 - 03:03 PM

What i am trying to attempt:

1) I need to find a way to pass choice into my inputMoney function allowing my program to know which drink the user is picking to reply the appropriate response to the amount of money needed to buy it.

2)I need to find a way to show my dailyReport function and total up the sum of all the drinks sold.



ERROR MESSAGE:
In function `void inputMoney(int, int)':
a function-definition is not allowed here before '{' token
expected `,' or `;' before '{' token
expected `}' at end of input

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;


	struct drink
	{
		  string drinkName;
		  double drinkPrice;
		  int drinks;
	 };
	 
	class drinkManager
	{
	private:
		   void inputMoney();
		   void dailyReport();
	public:
		   void displayChoices();
		   void buyDrink();
		   };	  
		   
		   
		   
   void displayChoices(int choice)
   {
	cout << "*Menu of drinks and prices*" << endl;
	cout << " Drink Name			Cost" << endl;
	cout << "(1)Cola				 .75" << endl;
	cout << "(2)Root Beer			.75" << endl;
	cout << "(3)Orange Soda		  .75" << endl;
	cout << "(4)Grape Soda		   .75" << endl;
	cout << "(5)Bottled Water		1.00" << endl;
	cout << "(6)EXIT					" << endl;
	cin >> choice;
	};
   
	void buyDrink(int)
	{
		 void inputMoney();
	}
   
  
   void inputMoney(int qty, int choice)  
		{
	   double price = 0.0;
	   double change = 0.0;
	   
			if(qty = 0)
			cout << "Sorry, currently sold out." << endl;
		   
			cout << "Please remove change" << endl;
			cout << "Please enter choice of beverage" << endl;
			cin >> choice;
			cout << "Please enter money or (6) to EXIT" << endl;
			cin >> price;
		   
			if (choice = 6)
			{
			cout << "Please remove change" << endl;
			}
		   
			if (choice = 5)
			{
			   if (price < 1)
			   {
				 cout << "not enough change, please remove change from slot" << endl;
				 }
			   else
			   double change = price - 1;
			   if (change = 0)
			   {
				 cout << "Thank you, enjoy" << endl;
				 }
			   else
			   {
				 cout << "Change: " << change << endl;
				 cout << "Thank you, enjoy" << endl;
				 }
			}
			if (choice <= 4)
			{
			   if (price < .75)
			   {
				 cout << "not enough change, please remove change from slot" << endl;
			   }
			   else
			   double change = price - .75;
			   if (change = 0)
			   {
				 cout << "Thank you, enjoy" << endl;
				 }
			   else
			   {
				 cout << "Change: " << change << endl;
				 cout << "Thank you, enjoy" << endl;
				 }
		   }
		   
			void dailyReport(int, int)
			{
		   
				 drink report[4];
					drink[0].Name = Cola,		  price = 0.75; qty = 20;
					drink[1].Name = Root Beer,	 price = 0.75; qty = 20;
					drink[2].Name = Orange Soda,   price = 0.75; qty = 20;
					drink[3].Name = Grape Soda,	price = 0.75; qty = 20;
					drink[4].Name = Bottled Water, price = 1;	qty = 20;
					
					
	   
   );
{
	 int main()
	 int choice = 0;
	 int quit = 6;
	 int qty = 0;


   

	system ("PAUSE");
	return 0;
}	


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1