Assignment 06

Due: Friday, Oct. 14, 2016 at noon 100 pts

You know how to submit; do it in the usual way. However, this time you will submit multiple files for this programming project. The cssubmit script will work as usual, picking up all .cpp and .h files in the current directory. So, make sure you have created a separate directory for your hw 6 program. Do not create sub-directories in the hw6 directory.

Background: The background for hw 6 is hw 4. That's right, you are going to rewrite hw #4, but this time using functions. And, there are to be modifications. You are going to code a rude vending machine that has a pension for snarky comments and a mind of its own.

Specifications: For this program, you will fulfill all the requirements of hw 4, but this time you will make judicious use of functions to simplify your code. Thus, with proper use of functions, you will simplify the main function, delegate tasks, avoid repeated code, et. ... all good things functions do for you. You will be graded on how well you do this. The way you choose your functions will be up to you; we are not going to dictate them to you. Make your decisions carefully. Furthermore, you are to compose this program in multiple files as you learned in your lecture. And, you are now required to accompany all function prototypes with appropriate documentation as you were shown in lecture.

First, change the initial quantities of the roots all to 12 except the first option; keep it at 5.

In addition, you will include the following modifications in the functionality. This will be a hoot!

  • First, you will write your code to randomize the menu choice. Yeah, we know, this is really contrary to the norm, but oh well...... So, when the user inputs the menu choice, your code will assign its choice by randomly choosing between and including 1 and 7 (that's right, one more than legal).

  • Next, you will write your code to output a message along with this menu choice that follows this rule:

    • if the user's choice matches the (value of) your program's random choice, then the message is "Fine! ... but you're gonna be sorry."

    • otherwise, the message is randomly chosen from the following list of possibilities, followed by the name of the item corresponding to the program's choice.

      • "No, you really want "

      • "As my uncle Hal would say, "I can't do that for you, Dave. You want " "

      • "Only a loooooser would want THAT. Try this instead: "

      • "WRONG! I'm sure you meant to pick "

      • "PPpfffffttt. I think you need "

      • "Only idiots choose that. Better to have some "

      • "Tss, you must be Homer! Only Homer would want that. Lisa's preference is "

  • Furthermore, when it comes to ordering the amount of the item so chosen, your code will prompt and read in an amount as usual. But, your code will randomly generate a number between and including 1 and twice what the user inputs, and uses this new amount in the following bullet.

  • This machine-chosen amount will be included in an output message chosen accordingly:

    • if the user's input matches the program's choice, output "I can do that ... "

    • otherwise,

      • if the program's choice is less than user's input, output "That's waayyy too much for you. You want "

      • if the program's choice is greater than user's input, output "Naw naw naw, you need "

      • In both the foregoing cases, follow the message by how many the program chose.

  • And last, but not least, your program is to calculate the tax following the "trickle-down principle"

    • if the subtotal is less than $100, tax is 50%

    • if the subtotal is from $100 up to and including $300, tax is 27%

    • if the subtotal is above $300, tax is 2%... you know, like 2% malk.

As an example of how all these modifications might play out, you could have this happen:

user chooses option 2, Mandrake. But your program randomly changes that choice to 4 (Square Root) and then says, "Only idiots choose that. Better to have some Square Roots". Next, your program would prompt for how much. The user might enter 5, whereupon your program generates randomly, say, 8 (a number between 1 and 10). Then outputs "Naw naw naw,you need 8". The menu is again presented as usual. And, of course, if the program is trying to sell you more of an item than is in stock, your old code should handle it appropriately. So, in this example, if there was only 6 Square Roots, your program would say something like, "we only have 6 of the 8 you want".

This insanity would continue until your program's randomness lands on 6, the quit option. (The user might pick quit, but your program might not let them!) Of course, the subtotal, tax, and total is then computed and etc.

Notes: A solution has already been posted for hw 4. You should try to avoid using it. Use your code from hw 4, corrected if need be. If your hw 4 solution was so bad that you must use the posted code, be sure to make note of that in the comment header in main - cite Dr. Leopold as the author of the code.

There's a lot of code in this program, so get started immediately! You might have to be clever how you code this. A suggestion: start with your hw 4 code and break it up into functions, then add the modifications. This might help you.

Also, if you want to add to the list of snarky remarks that your vending machine says, you can....but make them "clean".

Important: There is one function that you are required to have in your program. You should write a my_rand() function (not necessarily with that name) that has two parameters: one for the lower limit and one for the upper limit on the return value. Thus, calling myrand(46, 99); would return a random number between 46 and 99, inclusive. This makes coding easier.

Also: You are required to write at least one function that uses pass-by-reference parameters.

When you submit: As you know, the submit script will compile and run the program. First, pick an illegal option, say -9, as a menu choice. Then, you are to choose the options of your menu in order (repeating if necessary) until you end up quitting (remember, this will be up to the program as it randomly chooses what you actually get!). For each choice, you will ask for 4 as the quantity you want. Also, if by chance your program chooses to quit within the first 3 presentations of the menu (unlikely, though possible), then just submit again until you get at least 4 presentations of the menu.

And, as usual, if you have questions about this assignment, be sure to ask your instructor.