Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bottled Water $1.50 6. Quit Drink Machine Please make a selection 1 How much money has been inserted: $5 Do you still want to make a purchase? (Y / N) : y Here is your Cola, and your change of $4.00 : $1.00 : $1.00 : $1.00 : $1.50 Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bottled Water : $1.50 : $1.00 : $1.00 : $1.00 : $1.50 6. Quit Drink Machine Please make a selection : 2 How much money has been inserted: $6 Do you still want to make a purchase? (Y / N) : y Here is your Root Beer, and your change of $5.00 Drink

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

CTT

write cplus programs for exercises 14(Drink Machine Simulator) on page 590.
14. 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
Cost Number in Machine
1.00
20
Root beer
1.00
20
Orange soda 1.00
Grape soda
Bottled water 1.50
20
1.50
20
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
daily
Report, 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 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:
• all 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.
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.
For exact input output messages and menu choices, please refer to the test cases file below.
Transcribed Image Text:write cplus programs for exercises 14(Drink Machine Simulator) on page 590. 14. 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 Cost Number in Machine 1.00 20 Root beer 1.00 20 Orange soda 1.00 Grape soda Bottled water 1.50 20 1.50 20 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 daily Report, 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 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: • all 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. 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. For exact input output messages and menu choices, please refer to the test cases file below.
TEST CASE1:
Drink Machine Menu
1. Cola
2. Root Beer
3. Orange Soda
4. Grape Soda
5. Bottled Water : $1.50
6. Quit Drink Machine
Please make a selection : 1
: $1.00
: $1.00
: $1.00
: $1.50
How much money has been inserted: $5
Do you still want to make a purchase? (Y/ N) : y
Here is your Cola, and your change of $4.00
Drink Machine Menu
1. Cola
2. Root Beer
3. Orange Soda
4. Grape Soda
5. Bottled Water : $1.50
6. Quit Drink Machine
Please make a selection : 2
: $1.00
: $1.00
: $1.00
: $1.50
How much money has been inserted: $6
Do you still want to make a purchase? (Y / N) : y
Here is your Root Beer, and your change of $5.00
Drink Machine Menu
1. Cola
2. Root Beer
3. Orange Soda
4. Grape Soda
5. Bottled Water : $1.50
6. Quit Drink Machine
Please make a selection : 3
: $1.00
: $1.00
: $1.00
: $1.50
How much money has been inserted: $4
Do you still want to make a purchase? (Y / N) : y
Here is your Orange Soda, and your change of $3.00
Drink Machine Menu
1. Cola
2. Root Beer
3. Orange Soda
4. Grape Soda
5. Bòttled Water : $1.50
6. Quit Drink Machine
Please make a selection : 4
How much money has been inserted: $8
Do you still want to make a purchase? (Y/ N) : y
Here is your Grape Soda, and your change of $6.50
: $1.00
: $1.00
: $1.00
: $1.50
Drink Machine Menu
Transcribed Image Text:TEST CASE1: Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bottled Water : $1.50 6. Quit Drink Machine Please make a selection : 1 : $1.00 : $1.00 : $1.00 : $1.50 How much money has been inserted: $5 Do you still want to make a purchase? (Y/ N) : y Here is your Cola, and your change of $4.00 Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bottled Water : $1.50 6. Quit Drink Machine Please make a selection : 2 : $1.00 : $1.00 : $1.00 : $1.50 How much money has been inserted: $6 Do you still want to make a purchase? (Y / N) : y Here is your Root Beer, and your change of $5.00 Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bottled Water : $1.50 6. Quit Drink Machine Please make a selection : 3 : $1.00 : $1.00 : $1.00 : $1.50 How much money has been inserted: $4 Do you still want to make a purchase? (Y / N) : y Here is your Orange Soda, and your change of $3.00 Drink Machine Menu 1. Cola 2. Root Beer 3. Orange Soda 4. Grape Soda 5. Bòttled Water : $1.50 6. Quit Drink Machine Please make a selection : 4 How much money has been inserted: $8 Do you still want to make a purchase? (Y/ N) : y Here is your Grape Soda, and your change of $6.50 : $1.00 : $1.00 : $1.00 : $1.50 Drink Machine Menu
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Storage Devices
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education