Question
Write a program that simulates a soft drink machine. The program should use a structure that stores the following data: Drink Name Drink Cost Number
Write a program that simulates a soft drink machine. The program should use a structure that stores the following data: Drink Name Drink Cost Number of Drinks in Machine This is a new data type that must be defined at the file level. That is, "outside of main()". The program should create an array of five structures. This record struct should be declared "inside of main()". The elements should be initialized with the following data: Drink Name Cost Number in Machine ---------- ---- ----------------- Cola .75 20 Root Beer .70 15 Lemon-Lime .65 10 Grape Soda .55 3 Cream Soda .50 2 Write a Function, displayMenu(), that displays the following menu on the Console screen. *** Drink Machine Menu *** 1) Cola 0.75 2) Root Beer 0.70 3) Lemon-Lime 0.65 4) Grape Soda 0.55 5) Cream Soda 0.50 Write a Function, getChoice(), that asks the user to select a drink from the menu displayed. Verify that a VALID selection was entered. For the case where an INVALID value is entered, construct a loop where the user must keep entering a value until a VALID value is entered. The function must only return a VALID value to the calling program. VALID Selections are: ( 1 - 5 ). Write a Function, transaction(), to perform the tasks: 1) Accepts user drink selection(from getChoice()) as the value for an argument to the function. 2) First, check to see if the selected drink is sold out, if it is,
then display a message: "Sorry, that selection is sold out." and exit out of this function. 3) Prompt the customer to enter the amount of money for the drink selected. Make sure the customer entered at least enough for the selected drink, and no more than $1.00. (a) When the user enters an amount of money, do not accept negative or zero values or values greater than $1.00. (b) Do not accept amount less than the price for the drink. "There are no FREE DRINKS here". 4) Dispense the drink. Display a message. 5) Calculate any change that is due. If change is due, give it to the customer. Display a Message. 6) Decrease the number of cans of the selected drink currently in the machine. 7) Display the number of cans of this drink remaining in the machine. /********************************************************************* Program Structure should follow this pattern. *********************************************************************/ Define a struct data type for a Drink before main(). Declare array of structs of type Drink and initialize in main(). Create a flag-controlled loop to simulate the Drink Machine. while( not done ) { call displayMenu() function call getChoice() function call transaction() function } /*********************************************************************** Example console output for a Lemon-Lime selection *********************************************************************** *** Drink Machine Menu *** 1) Cola 0.75 2) Root Beer 0.70 3) Lemon-Lime 0.65 4) Grape Soda 0.55 5) Cream Soda 0.50 Enter your Selection (1-5): 3
Enter an amount of money: 1 Thump, thump, thump, splat! Enjoy your Lemon-Lime Change calculated: 0.35 Your change, 0.35 has just dropped into the Change Dispenser. There are 9 drinks of that type left. Are you finished? (y/n) : y ***********************************************************************/ ---------------------------------------------------------- DEMONSTRATE following TEST CASES: SHOW the results of your User Console Dialogs. Be sure to IDENTIFY and delineate your Test Cases. ---------------------------------------------------------- 1) Select one(1) Cola 2) Select one(1) Root-Beer 3) Select one(1) Lemon-Lime 4) Select one(1) Grape-Soda 5) Select two(2) Cream-Soda 6) Select Cream-Soda -- Verify "Sold-Out" Response 7) Enter a Negative amount -- Verify "Invalid-Value" Response 8) Enter a Zero(0) amount -- Verify "Invalid-Value" Response 9) Enter an amount > 1.00 -- Verify "Invalid-Value" Response 10) Make Invalid Drink Selection -- Verify "Invalid-Drink" Response 11) When Valid drink is selected -- Verify drinks left in machine. 12) When Valid amount is entered -- Verify correct change was dispensed. 13) Enter an amount less than the drink price -- Verify Message. ************************************************************************
PLEASE WRITE THE PROGRAM USING C++ LANGUAGE .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started