Assignment 04

Due: Tuesday, Sept. 27, 2016 at noon 100 pts.

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the

command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.Background: Our environmentalist hero, Lisa, is in the news. Lisa continues down the path of environmental righteousness! Yes, she is going to create a vending machine to set up at the Snax-o-thon....you know, where weird animals are fed and tortured by weird music. The vending machine will dispense homeopathic1 remedies/supplements. The program you will write will run the machine (not really....but you need to write it anyway). The proceeds from the machine will go towards funding fagales fagacae quercus empaths' (tree huggers) dissident activities (hugging trees).

Specifications: Your program is to first have the user input their name (first name only - and remember no white space). The name entered should be used in the friendly output your program generates. It is to then

Note that the price of (one unit of) each item is listed with the item. Your program should prompt the user to enter an indication of an item to purchase until the Quit option is chosen. When an item is chosen, the program should prompt the user for the number of units of that item the user wishes to buy. This will be added to their total purchases, and the menu is presented again for further purchases to tally. When the quit option is chosen, the program presents the final total dollar amount of purchases (you don't need to output an itemized bill, just the subtotal), calculate and add the 16% tax, and give the final total bill. (WOW! 16% tax! Well, no one else is going to fund tree huggers.) The tax should be rounded before adding to the total. Finally, your program will prompt for amount tendered (given by the user - sorry, no credit cards accepted, especially Discover), and calculate the amount of change to be given. Of course, if the user enters not enough, an error should result.....and the program present the total bill again.

Once the (possibly cheapskate) user coughs up enough money, end the program with an appropriate tree-hugging message.

Detail: Ok, that was easy. There's more to consider....always a catch. For each item, you will have a present inventory. These are the amounts the machine will start out with (you know, limited capacity)

present a menu of items to purchase from Lisa. It should contain the items listed below and appear in a similar fashion: Roots 'n Stuff

-----------------

1. Ginko Root ($4.50)

2. Mandrake Root ($1.23)

3. Ginseng Root ($2.39)

4. Square Root ($99.98)

5. Vitamin R Root ($0.78)

6. Quit

If the user insists on requesting an item NO LONGER AVAILABLE, then your program should output some snarky message about their apparent IQ and then re-present the menu. Furthermore, in such a case, your program should not ask for a number of items to buy; that would be silly.

Note: For those of you who don't know how to (mathematically) round a number, here it is. Simply add 1/2 of the unit you wish to round to and then chop. So, if you wish to round a monetary amount to the nearest penny, you will add 0.5¢ and then chop.

Also, since you will be displaying dollar amounts, it's bad form to have $3.50 come out as $3.5. So, put this code at the top of your main after declarations and it will force exactly two decimal places to be shown always.

cout.setf(ios::fixed);

-----------------

1. Ginko Root ($4.50)

2. Mandrake Root ($1.23)

3. Ginseng Root ($2.39) NO LONGER AVAILABLE

4. Square Root ($99.98)

5. Vitamin R Root ($0.78)

6. Quit

Thus, if the user desires to purchase fewer units of any item than is present in inventory, there is no problem; you make your tallies and go on. But if the user requests to buy more units than present in inventory, your program will only sell/provide what is indeed in inventory and charge the appropriate amount, and present a message stating as much (that only part of the order is filled). Now the interesting part. Once the machine has been depleted of an item, your menu should reflect this fact by appending to the end of the corresponding entry in the menu "item no longer available". So, if you ran out of Genseng, your menu would appear

Roots 'n Stuff

Vitamin R 8

Square 11

Ginseng 9

Mandrake 4

Ginko 5

Optionals: If the foregoing demands on your time are insufficient to satisfy your youthful coding exuberance, then try these ideas. But, only work on these if you have the time because we'll give you NO extra credit for it.

  1. Print out the required bills and coins for making the change.

  2. Make your menu so that it removes the listing of a depleted item and renumbers the remaining entries appropriately. This is tricky....very tricky.

If you are still bored after doing these, write a new operating system.

When you submit:

  1. enter a funny name

  2. choose item 7 from the menu (this better give an error!)

  3. choose item 2 and request -3

  4. choose item 2 and request 3

  5. choose item 4 and request 7

  6. choose item 2 and request 5

  7. choose item 1 and request 8

  8. choose item 2

  9. quit

  10. enter $500 as amount tendered to pay the bill

  11. enter $900 as amount tendered to pay the bill

1We have NO idea what this means. If anyone out there does, please don't tell us....ignorance is bliss.

cout.setf(ios::showpoint); cout.precision(2); This is magic code. Accept it. We'll tell you how it works near the end of the semester.