Question: solve it in C++ and with comments please WORKING WITH ARRAY OF STRUCTURES / FUNCTIONS Create a program to simulate a vending machine. Define a

solve it in C++ and with comments please

WORKING WITH ARRAY OF STRUCTURES / FUNCTIONS

Create a program to simulate a vending machine.

Define a structure called Item to hold the following information about each item:

Description

Price

Quantity in stock

Quantity sold

In main,create an array of these structures to represent the vending machine items. (Use a constant for the size of the array so it is easy to change). Initialize the data in the array. You can choose the number of items, the item descriptions, prices, in stock. Remember to start sold at 0 for each item.

Your application will:

1. Show the items available for purchase with a number by each one. The first item will be numbered as 1, but note that it is stored in element 0 of the array. (DO NOT make the array one bigger and ignore element 0). This should be done by a function.

2. Process a VALID purchase (valid item number, enough money, product in stock): a. User selects item b. User enters money c. Make sure there is enough money and the item is in stock. If so, display the item name. If there is change, show that

3. When all orders ended, print sales report. Should be done by a function.

4. Print items that need to be re-ordered. Should be done by a function.

You should create at least 3 functions:

showItems to print the items in the array

reportSales to print the sales report

reporReorders to print items that need to be re-ordered

Validation needed: valid item, enough money, product in stock. Give appropriate error messages as needed.

See sample output below, but DO NOT focus on going straight to sample output. Work on one specific thing at a time. Here is a suggested test plan. Remember to do testing EACH TIME.

1. Create the structure, array, initialize data, show the numbered items in vending machine. (create a function, or do without function then refactor to use a function).

2. Process a SINGLE purchase to make sure you have the proper processing steps: a. Prompt for valid item number to purchase. b. Enter amount of money. Loop to validate that there is enough money. c. Print the item and show change if any.

3. Add loop to process multiple orders, still valid choices only.

4. Modify process to check stock, give error message if out of stock. Update stock and sold.

5. Add validation loop for item number selected.

6. Write and test function to print sales report

7. Write and test function to print reorder report

Sample Output

VENDING MACHINE

1 chips 0.75

2 reeses 0.90

3 gummies 0.85

Enter item number or -1 to quit: 1

Enter money: .70

Insuficient, re-enter: .75

Dispensing product: chips

Enter item number or -1 to quit: 3

Invalid selection, re-enter: 1

Enter money: 1

Dispensing product: chips

Your change: 0.25

Enter item number or -1 to quit: 1

Item not in stock

Enter item number or -1 to quit: 2

Enter money: 1

Dispensing product: reeses

Your change: 0.10

Enter item number or -1 to quit: -1

SALES REPORT

ITEM SOLD

chips 2

reeses 1

gummies 0

Total sales: $2.40

REORDER REPORT

Items that need to be restocked

chips

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!