Due: Wednesday, Oct. 5, 2011, 8:00 a.m., 100 points
Note the due date and time!
For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to electronically submit a file to for this course, first change to the directory in which the file resides and then type in, at the UNIX prompt, the command:
cssubmit 53 section_letter assignment_number
Be sure that only the file you want to submit is in that directory - make a directory for every assignment! Remember that the submit system will deliver every .cpp file in the current directory to me, so you should only have the file for hw 4 in that directory. 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: Inspired by your abilities to code away his problems, and the fact that his and Chief Wiggums 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.
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". 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:
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 relevent, 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.
When you submit:
enter the info listed above in the example output, but do so in this order: Muntz, Tauritz, Wilkerson, Price, Szalapski
print 170
(attempt to) delete 102
delete 170
print all
(attempt to) add 344
add 150 Bobinski 7 (texts) $100
print 183
quit
As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutor.