declare ALL variables at the beginning of the program to make the program easier to read and understand. Type in C++

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

declare ALL variables at the beginning of the program to make the program easier to read and understand. Type in C++

**CS2010 - Program 3: Vending Machine**

**Program Description:**
We have a vending machine which sells 4 different items: Bottled-water, Lemonade, Cola, and Root-beer. For each item (except the bottled-water), there are two types: Light or Regular. This machine accepts $1, $5, and $10 bills as well as quarters, dimes, nickels, and even pennies. The customer can insert payment up to 10 dollars. Once a sufficient payment is received, the machine gives the item and the change back if needed. The cost of each item is:

1. Bottled-water - $1.25
2. Lemonade - $1.35
3. Cola - $1.75
4. Root-beer - $1.55

Write a C++ program that first displays a menu with the four items and their prices on the screen, then prompts the user to select an item by entering the choice code of 1 to 4. Add another choice code of “5” for the user to “Exit”. If the user enters 5 as the choice code, then the program will display “Goodbye” and stop execution. Otherwise, if the selected item is not a bottled-water, it then asks the user to enter a letter indicating the type of either Light or Regular. At last, the user will enter the payment amount.

The program validates the user inputs by making sure that the item selection is between 1 and 5, and the type selection is either L(l) or R(r) for non-water items. Appropriate error messages should be displayed for invalid selections. After that, the program checks for sufficient payment. If the payment amount is greater than or equal to the cost of the selected item, the program does the calculation for eventual change to pay back.

**Input:**

- A single digit choice code between 1 and 5
- A character L (or l) or R (or r) indicating Light or Regular type for non-water drinks only
- Payment amount
- Additional payment amount if the payment entered was insufficient

**Input Validation:**

- Your program should prompt the user for proper inputs, and validate all user inputs using loops.
  - If any invalid input is found, your program should display a proper message informing the error, then display the menu and prompt again to accept next input until a correct input is received.
  - If the
Transcribed Image Text:**CS2010 - Program 3: Vending Machine** **Program Description:** We have a vending machine which sells 4 different items: Bottled-water, Lemonade, Cola, and Root-beer. For each item (except the bottled-water), there are two types: Light or Regular. This machine accepts $1, $5, and $10 bills as well as quarters, dimes, nickels, and even pennies. The customer can insert payment up to 10 dollars. Once a sufficient payment is received, the machine gives the item and the change back if needed. The cost of each item is: 1. Bottled-water - $1.25 2. Lemonade - $1.35 3. Cola - $1.75 4. Root-beer - $1.55 Write a C++ program that first displays a menu with the four items and their prices on the screen, then prompts the user to select an item by entering the choice code of 1 to 4. Add another choice code of “5” for the user to “Exit”. If the user enters 5 as the choice code, then the program will display “Goodbye” and stop execution. Otherwise, if the selected item is not a bottled-water, it then asks the user to enter a letter indicating the type of either Light or Regular. At last, the user will enter the payment amount. The program validates the user inputs by making sure that the item selection is between 1 and 5, and the type selection is either L(l) or R(r) for non-water items. Appropriate error messages should be displayed for invalid selections. After that, the program checks for sufficient payment. If the payment amount is greater than or equal to the cost of the selected item, the program does the calculation for eventual change to pay back. **Input:** - A single digit choice code between 1 and 5 - A character L (or l) or R (or r) indicating Light or Regular type for non-water drinks only - Payment amount - Additional payment amount if the payment entered was insufficient **Input Validation:** - Your program should prompt the user for proper inputs, and validate all user inputs using loops. - If any invalid input is found, your program should display a proper message informing the error, then display the menu and prompt again to accept next input until a correct input is received. - If the
**Process**

Once all inputs are validated and sufficient payment is received, the program will calculate the exact change back in number of bills and coins. Only display the bills and coins that are applicable in the change.

**Output**

The program then displays a message like the following one:

```
Here is your Regular Cola!
Paid:      $ 10.00
           $ 8.30
Change Back: 
           1   Five Dollar Bill
           1   Dollar Bill
           1   Quarter
           1   Nickel
```

**Test Cases:**

A test case is a scenario of user inputs for verifying the correctness of the program. You should always test your program with sufficient test cases. For example, you must test your program with various combinations of item selections and type selections. You must also test your program with inputs that are invalid. For payment amount, you should consider at least each of the following probable cases where the user enters:

- Invalid menu choice
- Invalid drink type (L or R)
- Insufficient payment
- Exact change
- Dollar bills
- Five dollar bill
- Ten dollar bill

**Program Documentation & Style:**

1. Declare all constants and variables that your program uses at the beginning of your program.
2. Your program should include two types of comments. BE SPECIFIC!
   - **Header comments** at the beginning of your program including lines with:
     - Your name, course name, and class time
     - Program name (cmp2) and the date
     - **Purpose:** a sentence or two explaining the purpose of the program
     - **Input:** a description of the input data needed by the program when you run it
     - **Processing:** a description of the processing (calculations) done by the program
     - **Output:** a description of the results (output) produced by the program
   - **In-line comments:** There should be an in-line comment for each main step in your program. In general, this means at least one comment with each group of C++ statements that handles the input, the processing, and the output steps of your program.
3. Use meaningful identifier names.
4. Include clear prompts for the user about entering the data.
5. Include clear descriptions of the results when you display them.
6. Format your output neatly.
Transcribed Image Text:**Process** Once all inputs are validated and sufficient payment is received, the program will calculate the exact change back in number of bills and coins. Only display the bills and coins that are applicable in the change. **Output** The program then displays a message like the following one: ``` Here is your Regular Cola! Paid: $ 10.00 $ 8.30 Change Back: 1 Five Dollar Bill 1 Dollar Bill 1 Quarter 1 Nickel ``` **Test Cases:** A test case is a scenario of user inputs for verifying the correctness of the program. You should always test your program with sufficient test cases. For example, you must test your program with various combinations of item selections and type selections. You must also test your program with inputs that are invalid. For payment amount, you should consider at least each of the following probable cases where the user enters: - Invalid menu choice - Invalid drink type (L or R) - Insufficient payment - Exact change - Dollar bills - Five dollar bill - Ten dollar bill **Program Documentation & Style:** 1. Declare all constants and variables that your program uses at the beginning of your program. 2. Your program should include two types of comments. BE SPECIFIC! - **Header comments** at the beginning of your program including lines with: - Your name, course name, and class time - Program name (cmp2) and the date - **Purpose:** a sentence or two explaining the purpose of the program - **Input:** a description of the input data needed by the program when you run it - **Processing:** a description of the processing (calculations) done by the program - **Output:** a description of the results (output) produced by the program - **In-line comments:** There should be an in-line comment for each main step in your program. In general, this means at least one comment with each group of C++ statements that handles the input, the processing, and the output steps of your program. 3. Use meaningful identifier names. 4. Include clear prompts for the user about entering the data. 5. Include clear descriptions of the results when you display them. 6. Format your output neatly.
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
Algebraic Expressions
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.
Similar questions
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