Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ probelm, please help! Create the state diagram for a soda dispenser machine. Model the system as a state machine. Then, write a program that

C++ probelm, please help!

image text in transcribed

Create the state diagram for a soda dispenser machine. Model the system as a state machine. Then, write a program that simulates the soda dispenser machine. The program will execute in a loop waiting for users to enter coins. The only acceptable values as input are .05, .10, and .25. Any other value will be rejected by the machine. The cost of a soda is $1 so the program must continue to accept values until $1 is reached, and at that point the soda is dispensed, and the system begins the process again. In the case where input goes above $1, the system must dispense the soda and return the difference to the user. The sample output for the success use case is provided below. Waiting for coin input (-1 to shutdown): .05 Total coin input: 0.05 Waiting for coin input (-1 to shutdown): .10 Total coin input: 0.15 Waiting for coin input (-1 to shut down): .25 Total coin input 0.4 Waiting for coin input (-1 to shutdown): .25 Total coin input: 0.65 Waiting for coin input (-1 to shutdown) .10 Total coin input: 0.75 Waiting for coin input (-1 to shutdown): .05 Total coin input: 0.8 Waiting for coin input (-1 to shutdown) .10 Total coin input: 0.9 Waiting for coin input (-1 to shutdown): .10 Total coin input: 1 Dispensing soda out with no change. Waiting for coin input (-1 to shutdown): -1 Shutting down... good by! An alternate use case that deals with an incorrect input is presented below. As seen, when the user enters the value of .35, the machine is able to detect it, displays an error message, and resumes execution of the state machine. This use case also shows the correct way of dealing with users inserting values higher than $1; in this case, the machine dispenses the soda and returns the excess value to the user. Waiting for coin input (-1 to shutdown): .35 Machine can only accept .05, .1, .25, or 1 as input! Waiting for coin input (-1 to shutdown): .25 Total coin input: 0.25 Waiting for coin input (-1 to shutdown): .25 Total coin input: 0.5 Waiting for coin input (-1 to shutdown): .25 Total coin input: 0.75 Waiting for coin input (-1 to shutdown): 1 Total coin input: 1.75 Dispensing soda out with 0.75 change... Waiting for coin input (-1 to shutdown): -1 Shutting down... good by! After completion of this problem, you should be able to master the following: Declaring and using variables Input/output in C++ using the and objects Input/output in C++ using the stream insertion and stream extraction operators Write programs that repeat blocks of code using the iteration statement Write programs that alter the flow of control using the multiple-selection statements Use the switch multiple-selection statement to implement a state diagram. Use to increase reliability and readability of programs Use conditional statements (e.g., , or) Understand how the, and keywords are used within statements Develop problem solving skills by design and implementing high-level state machines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

Build active verb-based sentences

Answered: 1 week ago

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago

Question

4. What actions should Bouleau & Huntley take now?

Answered: 1 week ago