The goal of this programming assignment is to complete a partially-written program by filling in functions and function calls as needed.
To begin, you will need to download the HW3 program template linked on the class website, provided in both source code (.cpp) and plain text (.txt) formats for your convenience. You will also need the plain text file, floats.txt, linked there as well. We will access this file using File I/O and the <fstream> library.
In this assignment, we will continue (and conclude) the currency theme of HW1 and HW2 by developing software that will "simulate" a vending machine. From the user's perspective, the program first greets the user and displays a main menu with all of the items offered for purchase and their respective prices. It then prompts the user to select an item for purchase, and then asks them for the number of such items that they want to buy. Then, it calculates the cost, prompts them to insert payment, and computes the change owed in US dollars and coins. Finally, it asks them if they would like to make another purchase, and loops back to the main menu if the user desires. Otherwise, it prints a friendly goodbye message and ends.
Behind the scenes, when the program first begins, it reads in the pricing information per product from a data file, and stores this information for later use in the program.
IMPORTANT: Do NOT alter any of the code in the template when submitting your final program. This assignment is designed to test your understanding of the concept of functions and C++ function syntax. Comments in the template highlight where you are intended to add your code. Changing any code in the template will result in a reduction on your grade. If you are unsure about this, please ask your TA before submitting your final program!
Looking at the requirements above, try to sketch out the "flow" of the program using either a diagram or a sequence of conditional statements written in pseudo-code. Mentally walk through each of the possible paths, and think about what conditions and calculations need to be performed. The template provided should help you in the process.
Start your program with comments based on your design and (the following cannot be emphasized enough..) add portions of code a little at a time. Compile and run your program on a regular basis, so you always have something that runs, even if it only does part of the job. Make sure you have completed the first task, e.g., printing your name to the screen, before you start writing code for the second task.
Hint: For this assignment, you are given a large chunk of code that will absolutely not compile from the beginning. You should comment out any code that won't yet compile and begin on the first spot in main() when you need to add your own code. Frequent use of 'cout' statements to print the values of variables to the screen before and after function calls can greatly help you keep the logical flow of the program in check as you write it.
Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. For debugging purposes, it is useful to "echo" any variables you input, and to print intermediate results as they are calculated.
Important! Make use the error-checking examples given in the template as a model for how you should introduce error-checking for any I/O with the user (that is, whenever you use a 'cin' statement, make sure you get GOOD input, not just ANY input!).
You should comment out your debugging code before you hand in your final version of the program.
When you have completed your C++ program, write a short report (less than half of a page long; a few sentences will suffice) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems?
Include this report in the comments at the top of your source code file.
FINALLY (this is new), when you are finished, run your full program from start to finish. Copy/paste the entire screen output from at least one full run of your program at the bottom of your source code. Use comments around this output (that is, /* and */) to ensure your program still compiles as-submitted after this addition.
To Submit Homework 3:
(Note: Do not add anything extra to the body of the email! And make sure your FULL name and uark ID number are printed out at the beginning of your program...)
The date/time-stamp on your email will be used to verify that you met the due date above. All late projects will receive reduced credit (10% off if less than 24 hours late, no credit if more than 24 hours late), so hand in your best effort on the due date.