binary vending machine program in C++. This machine is called binary since it sells only two...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
binary vending machine program in C++. This machine is called "binary" since it sells only two items of user's choice. The names, prices, and initial amount of these items will be defined by the user. Additionally, the vending machine will only accept dollars ($1) and quarters ($0.25) as payment. Thus, the price of each item must be a multiple of 0.25. Detailed Requirements: 1. Item definition The program should start by asking the user to enter the names and prices of two items, and the initial amount of each item available in the machine. The amount of each item should be greater than 0. The price of each item must be a multiple of 0.25. Re-prompt the user until a valid input is given. 2. Item purchase The user can then choose to buy an item or quit. When the user chooses to buy an item, the program should check if the item is available. If the item is not available, the program should then ask the user to choose a different item or quit, until a valid input is given. Otherwise, the program should prompt the user to insert coins, one at a time. The user can insert either a dollar or a quarter, or they can stop inserting coins. The program should keep track of the total amount inserted by the user and stop prompting as soon as the user has inserted enough money. 3. Payment calculation Once the user has finished inserting coins or decides to stop, the program should determine if the inserted coins are enough to buy the item. If it is, the program should dispense the item and return the change (if any), otherwise return all the inserted coins back to the user. 4. Update Item availability After a successful purchase, the program should update the available amount of the item in the machine. 5. Buy it again The user can repeat the process of buying an item or quit the program. Remember, if the chosen item is out of stock, the program should inform the user and prompt them to choose another item or quit. 6. Display Requirements Before each purchase, the program should display the items, their prices, and amounts available. After each coin insertion, the program should print the cost of the item and the total inserted coin amount. Example program run (User inputs are highlighted): Welcome to the Binary Vending Machine! Enter the name of the first item: Coke Enter the price of the first item (multiple of 0.25): 1.30 Invalid input! Enter the price of the first item (multiple of 0.25): 2.75 Enter the amount of the first item (great than 0): -5 Invalid input! Enter the amount of the first item (great than 0): 10 Enter the name of the second item: Snickers Enter the price of the second item (multiple of 0.25): 1.75 Enter the amount of the second item (great than 0): 5 Here are the items available in the machine: 1. Coke - $2.75 (10 available) 2. Snickers - $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 3 Invalid input! Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 1 Cost: $2.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $2.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: $2.75 Inserted: $2.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $3.25 Here is your Coke and your change of $0.50. Here are the items available in the machine: 1. Coke $2.75 (9 available) 2. Snickers $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 2 Cost: $1.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $1.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop):q Cost: $1.75 Inserted: $1.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: $1.75 Inserted: $1.50 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): s Cost: $1.75 Inserted: $1.50 You didn't insert enough money. Here is your money back: $1.50 Here are the items available in the machine: 1. Coke $2.75 (9 available) 2. Snickers $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 0 Thank you for using the Binary Vending Machine! Have a great day! (5 pts) Extra Credit 1 Handle all invalid user input, even data of the wrong type. i.e. Re-prompt the user if they enter "asdf" instead of 1 or 0. (5 pts) Extra Credit 2 Decompose your program into tasks and subtasks using functions. To help you with this, use the following: Make each function do one thing and one thing only. No more than 15 lines inside the curly braces of any function, including main(). Whitespace, variable declarations, single curly braces, vertical spacing, comments, output statements, and function headers do not count towards those 15 lines. ⚫ Functions over 15 lines need valid justification in comments. Do not put multiple statements into one line. binary vending machine program in C++. This machine is called "binary" since it sells only two items of user's choice. The names, prices, and initial amount of these items will be defined by the user. Additionally, the vending machine will only accept dollars ($1) and quarters ($0.25) as payment. Thus, the price of each item must be a multiple of 0.25. Detailed Requirements: 1. Item definition The program should start by asking the user to enter the names and prices of two items, and the initial amount of each item available in the machine. The amount of each item should be greater than 0. The price of each item must be a multiple of 0.25. Re-prompt the user until a valid input is given. 2. Item purchase The user can then choose to buy an item or quit. When the user chooses to buy an item, the program should check if the item is available. If the item is not available, the program should then ask the user to choose a different item or quit, until a valid input is given. Otherwise, the program should prompt the user to insert coins, one at a time. The user can insert either a dollar or a quarter, or they can stop inserting coins. The program should keep track of the total amount inserted by the user and stop prompting as soon as the user has inserted enough money. 3. Payment calculation Once the user has finished inserting coins or decides to stop, the program should determine if the inserted coins are enough to buy the item. If it is, the program should dispense the item and return the change (if any), otherwise return all the inserted coins back to the user. 4. Update Item availability After a successful purchase, the program should update the available amount of the item in the machine. 5. Buy it again The user can repeat the process of buying an item or quit the program. Remember, if the chosen item is out of stock, the program should inform the user and prompt them to choose another item or quit. 6. Display Requirements Before each purchase, the program should display the items, their prices, and amounts available. After each coin insertion, the program should print the cost of the item and the total inserted coin amount. Example program run (User inputs are highlighted): Welcome to the Binary Vending Machine! Enter the name of the first item: Coke Enter the price of the first item (multiple of 0.25): 1.30 Invalid input! Enter the price of the first item (multiple of 0.25): 2.75 Enter the amount of the first item (great than 0): -5 Invalid input! Enter the amount of the first item (great than 0): 10 Enter the name of the second item: Snickers Enter the price of the second item (multiple of 0.25): 1.75 Enter the amount of the second item (great than 0): 5 Here are the items available in the machine: 1. Coke - $2.75 (10 available) 2. Snickers - $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 3 Invalid input! Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 1 Cost: $2.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $2.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: $2.75 Inserted: $2.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $3.25 Here is your Coke and your change of $0.50. Here are the items available in the machine: 1. Coke $2.75 (9 available) 2. Snickers $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 2 Cost: $1.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $1.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop):q Cost: $1.75 Inserted: $1.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: $1.75 Inserted: $1.50 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): s Cost: $1.75 Inserted: $1.50 You didn't insert enough money. Here is your money back: $1.50 Here are the items available in the machine: 1. Coke $2.75 (9 available) 2. Snickers $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2, or 0 to quit): 0 Thank you for using the Binary Vending Machine! Have a great day! (5 pts) Extra Credit 1 Handle all invalid user input, even data of the wrong type. i.e. Re-prompt the user if they enter "asdf" instead of 1 or 0. (5 pts) Extra Credit 2 Decompose your program into tasks and subtasks using functions. To help you with this, use the following: Make each function do one thing and one thing only. No more than 15 lines inside the curly braces of any function, including main(). Whitespace, variable declarations, single curly braces, vertical spacing, comments, output statements, and function headers do not count towards those 15 lines. ⚫ Functions over 15 lines need valid justification in comments. Do not put multiple statements into one line.
Expert Answer:
Answer rating: 100% (QA)
cpp include iostream include string using namespace std Function to check if the price is a multiple ... View the full answer
Related Book For
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Given that a quantity Q(t) is described by the exponential growth function Q(t) = 400e0.01t where t is measured in minutes, answer the following questions. (a) What is the growth constant k? k = (b)...
-
An ASTM cast iron, grade 30 (see Table A24), carries static loading resulting in the stress state listed below at the critical locations. Choose the appropriate failure locus, plot it and the load...
-
Two circular oil spills are tangent to each other. If the distance between centers is 800 m and they cover a combined area of 1.02 10 6 m 2 , what is the radius of each? See Fig. 7.10. Fig. 7.10 -...
-
In years past, car frames were built as stiff as possible, but today's cars are built with "crumple zones" in the front and rear portions of the frame. What is the purpose of this design change?
-
Presented below are the financial statements of Rocastle Company. Additional data: 1. Depreciation expense was $6,000. 2. Dividends of $25,000 were declared and paid. 3. During the year, equipment...
-
What are the key architectural differentiators of MariaDB compared to its predecessor MySQL, particularly concerning storage engines, indexing mechanisms, and query optimization strategies ?
-
A number of cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) coordinate intersection. City names and locations are...
-
What are the similarities between the Maslows hierarchy theory and ERG theory?
-
If a student is found guilty of plagiarism, all of the following are possible consequences EXCEPT: The student will fail the course. The student will be expelled. The student will be suspended. The...
-
If you owe $10,000 and the APR is 14 percent, what monthly payment would you need to make to reduce your debt to zero within two years? (Round answer to 2 decimal places, e.g. 52.75.)
-
The traditional role of public relations was to communicate with: the media. employees. customers. shareholders.
-
Water has an index of refraction of 1.33. What is the angle of refraction if a laser beam strikes the surface of the water at 30 degrees above the surface of the water? Show your work.
-
Booher Book Stores has a beta of 0.. The yield on a 3-month T-bill is 5% and the yield on a 10-year T-bond is %. The market risk premium is 6.5%, and the return on an average stock in the market last...
-
Types of Job Performance Directions: For each scenario below identify the (1) type of job performance it is and whether you would use (2) objective or subjective criteria to measure it. 1) Henry is a...
-
Using the theoretical sampling strategy, how many samples of size 4 (n = 4) can be drawn from a population of size: (a) N = 5? (b) N = 8? (c) N = 16? (d) N = 50?
-
1. What does a capital spending plan do? 2. What is an example of a capacity-related expenditure?
-
Can you think of instances when gaming behavior is appropriate in an organization?
-
What are some criticisms of the traditional budgeting model?
-
Example 11.3 introduces Klein's Model I. Use the data file klein to answer the following questions. a. Estimate the consumption function in equation (11.17) by OLS. Comment on the signs and...
-
Example 11.3 introduces Klein's Model I. Use the data file klein to answer the following questions. a. Estimate the investment function in equation (11.18) by OLS. Comment on the signs and...
-
Mike's Veneer Shop owns a vacuum press that requires annual maintenance. Mike has a contract to cover the maintenance expenses for the next 5 years. The contract calls for an annual payment of \(\$...
Study smarter with the SolutionInn App