We're Open
+44 7340 9595 39
+44 20 3239 6980

TO CREATE A PROGRAM THAT SIMULATES A VENDING MACHINE

  100% Pass and No Plagiarism Guaranteed

TO CREATE A PROGRAM THAT SIMULATES A VENDING MACHINE

CS2020 Program 2

Your assignment is to create a program that simulates a vending machine. Be sure to store your program in your class account on bgunix. Use the name pgm2.cpp for your program file.

Program Design: 
1. Declare a structure (e.g., Snack) with the data members snack name, cost and quantity. The struct should be declared before your main function and your function prototypes.

The steps below should be included in your main function. 
2. Declare an array of five Snack structures, each one initialized with the values shown in the table below. Initialize the data members of each struct with the name of the snack, the cost of the snack and the quantity of the snack available in the vending machine.

 

  Snack           Cost     Quantity

Reeses            1.00        4

M&Ms              1.00        2

Oreos             0.75        3

Doritos           0.50        3

Cheetos           0.75        2

An array of structs must be used to get credit for this assignment. See page 613 in the Gaddis textbook for an example of how to define an array of structs AND initialize the values of each element at the same time. Note that an initialization list can be used ONLY at the time you define the array.

3. Call a function to display a menu of options and accept a selection number from the user. The function accepts the array of structs as an argument, displays a list of the snacks and the cost of each, asks the user for a selection, validates the selection (using a validation loop) and returns the selection to the main function.

4. Create a while loop that continues until the user selection returned by the function in the previous step is 6 to end the snack machine program. In this loop:
a. Call a function that accepts the array of structs, the user`s menu choice and the total amount earned from transactions on this machine. This function should:
• Check to make sure the selected snack is in stock. Print a message if it is not and return.
• If the snack is in stock, get the amount of money entered by the user to pay for the snack.
• Use a validation loop to make sure the amount of money entered by the user is valid (do not accept negative values, values greater than $1.00 or values less than the cost of the snack).
• Calculate any change due and display it.
• Update the amount earned from snack sales.
• Update the inventory amount for the snack selected.
b. Call the function to get the user`s selection again to allow the user to enter a new selection.

 

    Sample Output

  1. Reeses 1.00
  2. M&Ms       1.00
  3. Oreos 0.75
  4. Doritos 0.50
  5. Cheetos 0.75
  6. End snack program

 

Please make your selection: 3

Enter payment amount: 1.00

Enjoy your Oreos snack!

 

Your change is 0.25


5. After the loop terminates, call a function to display the list of snacks, the cost of each and the quantity of each left. Also display the total amount earned for this vending machine before ending the program. Program Documentation & Style

1. Include function prototypes before the main function. Declare all constants and variables that your program uses at the beginning of the main function. 
2. Your program should include three types of comments. Use complete sentences. BE SPECIFIC!
a. Header comments at the beginning of your program including lines with:
- Your name, course name, and class time 
- Program assignment number, file name (e.g., pgm2.cpp) and due date
- Purpose: a sentence or two explaining the purpose of the program
- Input/Data: a sentence or two describing the input or initial data used by the program when you run it 
- Processing: a few sentences describing the processing and/or calculations done by the program
- Output: a description of the results (output) produced by the program
b. 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 handle the input, the processing and the output steps of your program. 
c. Function comments. A sentence or two should be included before each function definition to explain its purpose.
3. Use meaningful identifier names. 
4. Include clear prompts for the user about entering the data when appropriate.
5. Include clear, descriptive labels for output values.
6. Format your output neatly.

Turning in your programs

- Make sure you have completed your program according to the specifications given.
- Make a photo of your program by typing in the following commands at the prompt:

$ photo pgm2.log ( to start the photo utility)
$ pwd ( to identify your current directory)
$ ls -l ( to list all files in your directory – lower case Ls not ones)
$ ( to leave a few blank lines press the Enter key )
$
$ cat pgm2.cpp ( to show your C++ source code)
$ g++ pgm2.cpp ( to compile your program - creates a.out file)
$ a.out Enter the input values below when you run your program:
Selection Amount paid
3 1.00
5 1.00
4 .50
5 .75
1.00
1 1.50
-1.00
1.00
2 1.00

7

$ exit ( to end the photo session)


CS2020 Grading Rubric - Program 2

_______ Files named correctly (pgm2.cpp, pgm2.log) and in your class directory by the due time. All of the commands shown must be typed in during the photo session. Partial credit is given so be sure your photo log file is in your class account on bgunix by the due time even if the program is not completed. No credit given if program is turned in late.

_______ (2) Header comments complete, includes labeled sections identifying the Purpose, Input, Processing and Output

_______ (2) In-line/Function comments complete, uses good program style (meaningful data names, whitespace, indentation)

_______ (2) main function creates array of structs and includes sentinel-controlled loop to allow user to enter choices until done

_______ (3) Function to get user`s selection correctly displays snack list menu, gets user selection and validates it, returns selection to main function. Data aligned neatly in columns.

_______ (3) Function to process user`s selection checks for availability of snack, validates amount entered, calculates change, updates amount earned and quantity left

_______ (3) Function to display the snack list shows correct final quantities and total amount earned


_______ (15) Total Points


100% Plagiarism Free & Custom Written,
Tailored to your instructions


International House, 12 Constance Street, London, United Kingdom,
E16 2DQ

UK Registered Company # 11483120


100% Pass Guarantee

STILL NOT CONVINCED?

View our samples written by our professional writers to let you comprehend how your work is going to look like. We have categorised this into 3 categories with a few different subject domains

View Our Samples

We offer a £ 2999

If your assignment is plagiarised, we will give you £ 2999 in compensation

Recent Updates

Details

  • Title: TO CREATE A PROGRAM THAT SIMULATES A VENDING MACHINE
  • Price: £ 109
  • Post Date: 2018-11-09T10:09:13+00:00
  • Category: Assignment
  • No Plagiarism Guarantee
  • 100% Custom Written

Customer Reviews

TO CREATE A PROGRAM THAT SIMULATES A VENDING MACHINE TO CREATE A PROGRAM THAT SIMULATES A VENDING MACHINE
Reviews: 5

A masterpiece of assignment by , written on 2020-03-12

I have been taking help from Insta Research since 2015 and believe me, this place is incredible in giving the best help in assignments and essays. I also ask them to run plagiarism in my essays that I have written, and they always gave me accurate results. I am literally blessed to have a strong bonding with this site so that in any need of urgency, I contact them and find them always beside me. Thank you!
Reviews: 5

A masterpiece of assignment by , written on 2020-03-12

Writing is not my field. I take help from this website for my accounting assignment. The work is good and I scored good grades in it. Thank you from the bottom of my heart.