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 | Cost | Number in Machine |
Cola | 1.00 | 20 |
Root beer | 1.00 | 20 |
Orange soda | 1.00 | 20 |
Grape soda | 1.00 | 20 |
Bottled water | 1.50 | 20 |
The class should have two public member functions, displayChoices (which displays a menu of drink names and prices) and buy Drink (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
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 inputMoney function, passing it the patron’s drink choice.
• If the patron no longer wishes to make the purchase, return all input money.
• If the machine is out of the requested soda, display an appropriate “sold out” message and return all input money.
• If the machine has the soda and enough money was entered, complete the sale by 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.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
Database Concepts (8th Edition)
Starting Out With Visual Basic (8th Edition)
- Cruise Recreational Activities Example Recreational activities include things like aerobics, shuffle board, and swimming. Each activity is identified by an activity code and includes other information such as description. Classes are offered for each activity. A class is uniquely identified by a combination of the activity code and the day/time at which it is held. It is assumed that a specific class will never be offered for the same activity at the same day and time, although it could be offered on a different day and/or time. Other information about a class includes the enrollment limit and the current enrollment count. A class will never include more than one activity. A passenger can sign up for a class as long as there is sufficient room in the class. Passengers are identified by a unique passenger number. Other information stored about passengers includes name, address, and age. Passengers have no limit on the number and type of classes they can sign up for. When they…arrow_forwardC# language Create a Product class then create an object from that class using User Input. The program must have Constructor. please see picture for example output. Instead of first name and last name make it product name and product price and descriptionarrow_forwardIn previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing Dancing, Musical instrument, and Other. The class contains an auto-implemented property that holds a contestants name. The class contains fields for a talent code and description. The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The talent description is a read-only property that is assigned a value when the code is set. Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this years competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. The program prompts the user for names and talent codes for each contestant entered. Along with the prompt for a talent code, display a list of the valid categories. After data entry is complete, the program displays the valid talent categories and then continuously prompts the user for talent codes and displays the names of all contestants in the category. Appropriate messages are displayed if the entered code is not a character or a valid code.arrow_forward
- Dice Rolling Class In this problem, you will need to create a program that simulates rolling dice. To start this project, you will first need to define the properties and behaviors of a single die that can be reused multiple times in your future code. This will be done by creating a Dice class. Create a Dice class that contains the following members: Two private integer variables to store the minimum and maximum roll possible. Two constructors that initialize the data members that store the min/max possible values of rolls. a constructor with default min/max values. a constructor that takes 2 input arguments corresponding to the min and max roll values Create a roll() function that returns a random number that is uniformly distributed between the minimum and maximum possible roll values. Create a small test program that asks the user to give a minValue and maxValue for a die, construct a single object of the Dice class with the constructor that initializes the min and max…arrow_forwardA. Car Class Create a Python Program where you write a class named Car that has the following data attributes: • _ _year_model (for the car's year model) • __make (for the make of the car) • _ _speed (for the car's current speed) The Car class should have an _init_ method that accepts the car's year model and make as arguments. These values should be assigned to the object's _year_model and make data attributes. It should also assign 0 to the __speed data attribute. The class should also have the following methods: accelerate() The accelerate method should add 5 to the speed data attribute each time it is called. brake() The brake method should subtract 5 from the speed data attribute each time it is called. • get_speed() The get_speed method should return the current speed. Next, design a program that creates a Car object then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method…arrow_forwardpythonarrow_forward
- When data cannot be changed after a class is compiled, the data is identifier variable keyword constantarrow_forwardLab 2 – Designing a class This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Design a class named Computer that holds the make, model, and amount of memory of a computer. Include methods to set the values for each data field, and include a method that displays all the values for each field. For the programming problem, create the pseudocode that defines the class and enter it below. Enter pseudocode herearrow_forwardTrue or False Objects that are instances of a class can be stored in an array.arrow_forward
- In this program you will create a structure called class to hold the information of a class in Seneca college’s buildings. The information required for each class is as follows Campus name (like Newham or Seneca@york) Building name (like Victor Phillip Dahdaleh Building) floor (like 1 2 3 4 5, …) class code (like DB2109) size of class (40 60 25) has projector (yes/no, Y/N or 1/0) has podium (yes/no, Y/N or 1/0) has whiteboard (yes/no, Y/N or 1/0) The following is the beginning of the declaration of the structure Struct class{ Char campus[101]; Char building[101]; --- --- } Complete the above structure template based on the list of attributes provided careful with proper usage of . (dot) operator and -> (arrow) operator as this is the part of the code that gets the mark! void getClass (struct class* cl) Implement the following printClass void printClass(struct class cl) Your function should print the Class in the following format: Campus: NewhamBuilding:…arrow_forwardObject oriented programming Intellijarrow_forwardC++ Visual Studio 2019 Employee Class - Please submit just one file for the class and main to test the class. Just create the class before main and submit only one cpp file. Do not create separate header files.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT