1 answer

Q13 c++ if answering please do not write code in paragrapth form. 13. Drink Machine Simulator...

Question:

q13 c++
if answering please do not write code in paragrapth form.

13. Drink Machine Simulator Write a program that simulates a soft drink machine. The program should use a structure that stor

Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape Soda .80 20 Cream Soda .80 20 Each tim

Each time the program runs, it should enter a loop that performs the following steps: A list of drinks is displayed on the sc

13. Drink Machine Simulator 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 The program should create an array of five structures. The elements should be initialized with the following data: Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape Soda .80 20
Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape Soda .80 20 Cream Soda .80 20 Each time the program runs, it should enter a loop that performs the following steps: A list of drinks is displayed on the screen. The user should be allowed to either quit the program or pick a drink. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned and subtract one from the number of that drink left in the machine. If the user selects a drink that has sold out, a message should be displayed. The loop then repeats.
Each time the program runs, it should enter a loop that performs the following steps: A list of drinks is displayed on the screen. The user should be allowed to either quit the program or pick a drink. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned and subtract one from the number of that drink left in the machine. If the user selects a drink that has sold out, a message should be displayed. The loop then repeats. When the user chooses to quit the program it should display the total amount of money the machine earned. Input Validation: When the user enters an amount of money, do not accept negative values or values greater than $1.00.

Answers

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

// Defines a structure to store drink inventory
struct DrinkMachine
{
// Data member to store drink information
string drinkName;
double cost;
int numberInMachine;
};// End of structure

// Function to display drink information
void showDrinks(DrinkMachine dm[], int len)
{

cout<<"\n\n ******************** Drinks Available ********************\n";
cout<<left<<setw(8)<<"Index"<<setw(20)<<"Drink Name"<<setw(10)<<"Cost"<<setw(20)<<"Number In Machine"<<endl;

// Loops till number of drinks available
for(int c = 0; c < len; c++)
// Displays the current drink
cout<<setw(8)<<(c)<<setw(20)<<dm[c].drinkName<<fixed<<setprecision(2)<<setw(10)<<dm[c].cost
<<setw(20)<<dm[c].numberInMachine<<endl;
}// End of function

// Function to return valid drink name entered by the user
// Returns the index position
int validDrink(DrinkMachine dm[], int len)
{
// To store the number entered by the user
int no;

// Loops till valid index entered by the user
do
{
// Accepts drink name index from the user
cout<<"\n Enter the drink index number: ";
cin>>no;

// Checks if the number is greater than or equals to 0 and less than length
if(no >= 0 && no < len)
// return the index
return no;

// Otherwise displays error message
else
cout<<"\n\t Invalid index. Try again.";
}while(1); // End of do - while loop
}// End of function

// Function to return valid cost entered by the user
double validCost(DrinkMachine dm[], int len, double productCost)
{
// To store the number entered by the user
double amount;

// Loops till valid amount entered by the user
do
{
// Accepts amount from the user
cout<<"\n Enter the amount: ";
cin>>amount;

// Checks if the amount is greater than or equals to 1.0
if(amount >= 1.0)
// Checks if the amount is greater than or equals to the purchased cost
if(amount >= productCost)
// Returns the amount
return amount;
else
cout<<"\n Insufficient amount. Product cost is: $"<<productCost;
// Otherwise displays error message
else
cout<<"\n\t Invalid cost. Try again.";
}while(1); // End of do - while loop
}// End of function

// main function definition
int main()
{
// Creates an array of object and assigns data
DrinkMachine dm[] =
{
{"Cola", 75.0, 20}, {"Root Beer", 75.0, 20}, {"Lemon Lime", 75.0, 20},
{"Grape Soda", 80.0, 20}, {"Cream", 80.0, 20}
};// End of initialization

// Calculates number of records
int len = sizeof(dm) / sizeof(dm[0]);

int choice;
int index;
double amount;

// Loops till user choice is not 2
do
{
// Calls the function to display drinks information
showDrinks(dm, len);

// Displays menu and accepts user choice
cout<<"\n 1 - Pick a drink. \n 2 - Exit.

\n\t What is your choice? ";
cin>>choice;

// Checks if choice is 2 then stop the loop
if(choice == 2)
break;

// Otherwise checks if choice is 1
else if(choice == 1)
{
// Calls the function to accept valid drink
// Stores the return index
index = validDrink(dm, len);

// Checks if required drink quantity is not 0
if(dm[index].numberInMachine != 0)
{
// Calls the function to accept valid amount
amount = validCost(dm, len, dm[index].cost);

// Subtracts one quantity
dm[index].numberInMachine--;

// Checks if amount paid is greater than the product cost
if(amount > dm[index].cost)
// Calculates and displays change returned
cout<<"\n Take your change: $"<<(amount - dm[index].cost);
}// End of if condition

// Otherwise quantity is 0. Display error message
else
cout<<"\n Product is sold out.";
}// End of else if condition

// Otherwise invalid choice
else
cout<<"\n Invalid choice!!";

}while(1);// End of do - while loop
return 0;
}// End of main function

Sample Output:

Index 1 2 3 4 Drink Name Cola Root Beer Lemon Lime Grape Soda Cream Drinks Available Cost Number In Machine 75.00 20 75.00 20

.

Similar Solved Questions

1 answer
Covid-19 is an infectious disease caused by novel coronavirus and has its origin in Wuhan, China....
Covid-19 is an infectious disease caused by novel coronavirus and has its origin in Wuhan, China. of 4 pages (CBP25 Introduction to Social Sciences and Humanities Most people who get sick of Covid-19 will experience mild to moderate symptoms and recover without special treatment. In reference to the...
1 answer
2. A bed and breakfast place has annual fixed costs of $100,000 variable costs of 60%...
2. A bed and breakfast place has annual fixed costs of $100,000 variable costs of 60% of sales revenue and a tax rate of 30%. Owner wants an after tax net income of $35,000. What sales revenue must be achieved to provide $35,000 net income after tax? Prepare an income statement to confirm the calcul...
1 answer
PLEASE PUT SOLUTION IN THE SAME FORMAT AS THE IMAGE. THANK YOU! Exercise A-2 (Algo) Derivatives;...
PLEASE PUT SOLUTION IN THE SAME FORMAT AS THE IMAGE. THANK YOU! Exercise A-2 (Algo) Derivatives; interest rate swap; fixed rate debt [LOA-2] On January 1, 2021. LLB Industries borrowed $210,000 from Trust Bank by issuing a two-year, 12% note, with interest payable quarterly. LLB entered into a two-...
1 answer
ADVANCED MATERIAL Predicting qualitatively how entropy changes with temperature and volume For each system listed in...
ADVANCED MATERIAL Predicting qualitatively how entropy changes with temperature and volume For each system listed in the first column of the table below, decide (if possible) whether the change described in the second column will increase the entropy S of the system, decrease S, or leave Sunchanged....
1 answer
Java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter...
java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter n contains only odd digits (1, 3, 5, 7, or 9), and returns false otherwise. Zero is counted as an even digit whenever it appears inside the number. Remember that for a positive integer n,...
1 answer
How do you express #cos theta - sec theta + cot theta # in terms of #sin theta #?
How do you express #cos theta - sec theta + cot theta # in terms of #sin theta #?...
1 answer
Create a table describing acute tracheobronchitis, including clinical manifestations, and medical and nursing management.
Create a table describing acute tracheobronchitis, including clinical manifestations, and medical and nursing management....
1 answer
. Please explain the Gramm-Leach Bliley Act. You must explain the background and history of the...
. Please explain the Gramm-Leach Bliley Act. You must explain the background and history of the Act. 2. Research and discuss a case outside of the book and lecture notes in regard to the Gramm-Leach Bliley Act. 3. How would you define the major parts of the privacy requirements: the Financial Privac...
1 answer
This is how to question is give. A cell composed of a platinum indicator electrode and...
this is how to question is give. A cell composed of a platinum indicator electrode and a silver-silver chloride reference electrode in a solution containing both Fe2* and Fe3+ has a cell potential of 0.699 V. If the silver-silver chloride electrode is replaced with a saturated calomel electrode (S...
1 answer
Measured Wavelength for Hg vapor > 900 3. A student used a Measured Wavelength (nm) vs....
Measured Wavelength for Hg vapor > 900 3. A student used a Measured Wavelength (nm) vs. Actual Wavelength (nm) for Hg Vapor spectroscope to view the emission spectrum of Hg vapor, and plotted her measured wavelengths ly- axis) vs. the actual wavelengths (x-axis). The actual wavelength of ...
1 answer
Power Supply with Zener Voltage regulator D4 131 12 Vpk Vs 60 Hz 0° D2 D3 2. Simulate the bridge rectifier with three different filter capacitors(1uf, 5μF and 10μF) and observe output waveforms. Comp...
Power Supply with Zener Voltage regulator D4 131 12 Vpk Vs 60 Hz 0° D2 D3 2. Simulate the bridge rectifier with three different filter capacitors(1uf, 5μF and 10μF) and observe output waveforms. Compare ripple voltages, estimation vs. simulation values Plot v, and vout waveforms. Power Su...
1 answer
In this question, an amortization table is given. In this situation, you want to take out a 12 ye...
In this question, an amortization table is given. In this situation, you want to take out a 12 year loan for $215,000. The current interest rate is 5.75%, and you will make monthly payments. 1. Lets assume that you can only afford to pay $2,400 a month. With the same interest rate above, calculate t...
1 answer
Question 12 (20 points) The Federal Reserve hus a dual mandate of full employment and price...
Question 12 (20 points) The Federal Reserve hus a dual mandate of full employment and price stability. Oftentimes this mandate is challenging as there is a short term fradcoff betweon unemployment and inflation. From 2008 to 2015 nowever, infation was consistently below the target rate while unemplo...
1 answer
A wave has the following properties amplitude = 0.171 m, period = 0.508 s, wave speed...
A wave has the following properties amplitude = 0.171 m, period = 0.508 s, wave speed = 7.06 m/s. The wave is travelling in the x-direction. What is the equation for the wave? Y =...
1 answer
A 10 percent coupon bond has 15 years to maturity and could be called in two...
A 10 percent coupon bond has 15 years to maturity and could be called in two years. If the bond is called, investors will earn 4 percent. The call premium is one year of coupon payments. If coupon payments are made annually and par value is $1,000, what is the bond's yield to maturity? Multiple ...
1 answer
Can someone answer questios 1-13? nstructure.com/courses/11471/quizzes/231523/take Question 1 0.5 pts A cell spends most of its...
can someone answer questios 1-13? nstructure.com/courses/11471/quizzes/231523/take Question 1 0.5 pts A cell spends most of its life in what stage of the cell cycle? O Interphase O Prophase O Metaphase O Telophase O Cytokinesis D Question 2 0.5 pts TRUE or FALSE: Gap intervals are periods o...
1 answer
Crossfire Company segments its business into two regions-East and West. The company prepared a contribution format...
Crossfire Company segments its business into two regions-East and West. The company prepared a contribution format segmented income statement as shown below: Sales Variable expenses Contribution margin Traceable fixed expenses Segment margin Common fixed expenses Net operating income Total Company $...
1 answer
Write a net ionic equation to show that hydroiodic acid, HI, behaves as an acid in...
Write a net ionic equation to show that hydroiodic acid, HI, behaves as an acid in water....