Assignment 05

Due: Wednesday, March 4, 2020, at noon, 100 points

For this assignment, you will submit a single C++ compilable file containing a program written in C++. 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.

Background: Inspired by your abilities to code away his problems, and the fact that his, and Chief Wiggum's, attempt at standup humor flopped, Groundskeeper Willie has decided to return to his old job. But he has yet another project for you. He needs help keeping up with all the students' hallway lockers and their contents! He's going to first apply this program to one particular hallway, the "Pre-Prison Group" hallway, where Kearney, Jimbo Jones, and Nelson Muntz have their lockers.

Specifications: Once again, your program is to be menu driven. This is what your menu should look like:

menu heading ------------ 1. Add a locker 2. Print contents of a locker 3. Output all locker contents 4. Delete a locker 5. Quit There are n occupied lockers

Pick an option from above _ When option 1 (or a) is picked, then the user is prompted for the following information:

  • locker number (The lockers in this particular hallway will be numbered beginning with 101 and ending with 201. Thus, you know how many possible lockers there are, right?) If that locker number is already assigned, then an appropriate message should be output and input terminated.

  • student's last name only and with NO whitespace (spaces, tabs, newlines) in the name.

  • how many textbooks the locker contains.

  • how much money is in the locker.

When option 2 (or p) is chosen, then the program is to output the information about a locker that the user identifies by locker number. If the locker number is for an unoccupied locker, output an appropriate message.

When option 3 (or o) is chosen, a complete listing of the contents of all occupied lockers, in locker-number-order, is output.

When option 4 (or d) is chosen, the program is to read in a locker number from the user and that locker is to be "emptied" - that means it is no longer to be considered as being used by anyone. Of course, if a valid locker number is entered but it is not occupied, then an appropriate message is output.

When option 5 (or q) is chosen, I don't think we need to tell you what your program should do.

After each choice, excepting to quit, the menu is to be presented again. Each time the menu is presented, the number (count) of occupied lockers and the average number of texts (to two dec. places) contained therein is displayed too. If at any point in the run of this program, the total amount of money in the lockers exceeds $150, Willie robs them all and the program should reset monetary contents of all (occupied) lockers to $0.

Notes:

  • You are to use the c++ concepts that you have learned so far in this course. Do NOT use concepts we have not covered, such as functions. I hate to stanch creative thinking, but ... oh well. You will have your day in the sun for coding functions later.....like hw 6, and all the rest.

    • Since you will be outputting monetary values, you will want the output of, say, three and a half dollars to appear as $3.50 and not $3.5. To make your code do that, use the following magical code (we'll explain later):

      • cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);

    • Any output before this code is executed will have standard default output format (what you're familiar with); any output after this is executed will have exactly 2 decimal places for floats.

  • For this assignment, you are going to have to make some very serious code design decisions. You will be wise to think carefully about how to represent your data. Clearly, you will be using structs and arrays, and penalized if you don't. But how you store the information in your array is going to determine how you code the rest of the program. There are several ways to do this program, and you may find one way difficult and another way easy. The choice will be yours. To this end, you are welcome to include other variables associated with a locker if they are relevant, needed, and reasonable.

    • We're going to grade you on the format of your output, so make it nice! Here's an example of nice output. It doesn't have to be exactly like this, but it must formatted nicely for easy consumption.

      • Lockers ------- 101 Muntz 5 texts $4.56

    • 154 Price 0 texts $45.00 157 Wilkerson 89 texts $0.34 170 Szalapski 1 text $1.05 183 Tauritz 4500 texts $34.50 So, you get the idea.

Remember: When writing your code, be sure to:

  • Have your code in this and every program you write to "range check" or "cleanse" the input values.

  • Declare your variables with the APPROPRIATE type.

  • Use meaningful variable names.

  • Use proper spacing for indentations.

  • Use constant declarations where appropriate.

  • Include the comment block at the head of your file.

  • Comment code that needs it.

  • Be literate in your welcoming/signing-off messages and prompts and output.

As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutor.