Assignment 03

Due: Friday, Sept. 14, 2018 at noon 100 points

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: Krusty has had some complaints (well, nothing but complaints!, but I digress) about the choices on his menus lacking pizzaz. So, Krusty has decided to spice up his burger joint with a new menu every week. But, being the stupid, lazy sot that he is (hey, he's a Simpsons character), he tires of this chore easily and wants you to write a program to automatically generate a burger name and its price based on a 3-digit code. He would enter the code, and your program would spit out the burger name and what it should cost. He then puts that info on a sign board in the restaraunt. Thus, you could imagine him running your program each Monday morning as he is waking up, entering 3-digit numbers that come to him in his foggy state-of-mind, making his menu for the week.

Specifications: Your program will greet Krusty and ask him for a 3-digit code. This is to be read in as a single integer input; not as 3 separate inputs. If the code is more than 3-digits, it will reprompt until it is 3-digits. Then your program will examine each of the three digits to determine its meaning.

  • The first digit (hundreds digit) represents the number of beef1 patties on the burger.

  • The second digit represents the number of ounces (oz) of bacon2 on the burger.

  • The third (units digit) represents the number of pickle slices3 on the burger.

Each burger name generated will begin with "Krusty" (No, don't include the quote marks!) and end with "Burger". There will be three words between these, each reflecting the information in the digits. It works like this:

    1. # patties:

        • 0 -> an invalid entry. Krusty doesn't believe in burgers w/o patties. Reject such a code.

        • 1 -> "Single"

        • 2 -> "Double"

        • 3 -> "Triumph"

        • 4 or more -> invalid code

    2. # oz bacon:

        • 0 -> "Health-Master"

        • 1 -> "Bacon"

        • 2 -> "Wilbur"

        • 3 -> "Klogger"

        • 4 or more -> invalid code

    3. # of pickles:

        • 0 -> "Tasteless"

        • 1 -> "Pickly"

        • 2 -> "Garden-Fresh"

        • 3 -> "Kermit"

        • 4 or more -> invalid code

    4. Special Cases:

        • If the number of pickles is greater than or equal to the sum of the number of patties and oz. of bacon, call it the "Krusty Veggie Burger".

        • If the number of patties plus the oz. of bacon is equal to 6 and the number of pickles is either 0 or 1, call it the "Krusty Koronary Burger".

So, you can see that if he enters code 223, your program would spit out "Krusty Double Wilbur Kermit Burger" (Mmmmmmmm!). Nice. Entering 523 would generate an error message since Krusty doesn't (currently) put 5 patties on a burger.

Also, your program is to print out the cost of the burger. Follow this prescription:

  • Each patty costs $0.75

  • Each oz. of bacon costs $0.50

  • Each pickle slice costs $0.25

  • The buns cost $0.50 each (one bun is both a top and a bottom, so $0.50 for the whole burger), even though Krusty digs them out of the dumpster behind the bread store every night.

After that, your program is to reprompt Krusty (or whomever is running the Krusty Korp. at the time....hint hint) for another code, stating that 000 will end the program. This (and making sure the code entered is 3-digits) requires looping. At the time this program is assigned, we haven't yet covered that. It should be covered on Monday. However, you can add that code in later and do most of the program before learning loops.

Make sure that the output is "user friendly", unlike Krusty himself.

Remember: When writing your code, be sure to:

    • Use meaningful variable names.

    • Use proper spacing for indentations.

    • Use constant variable declarations where appropriate. (I can see that there should be at least a dozen constants in this program.)

    • 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.

    • Don't type past the 80th column.

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); cout.setf(ios::showpoint); cout.precision(2);

Note: Do not use the switch statement in your program.

When you submit the submit script will (attempt to) compile and execute your program in the process. This means that you will be the "user" of the program for that few minutes. Now, in order that the grader isn't driven crazy by a multitude of inputs/outputs, you will ALL input the same values so that he/she has uniform output to grade. They are:

    • 311

    • 331

    • 012

    • 000

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

1Well, it looks like beef. For a list of possible beef substitutes, contact the Springfield Sanitation Dept.

2No way! Krusty would never serve real bacon. Most likely it's chicken feet and fish scales bacon.

3Nooopppee! And you really don't want to know the truth.