Assignment 03

Due: Friday, Feb. 14, 2020 at 12:00 noon, 100 points

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, you will be using git. Remember to 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 when you submit it.

Background: Groundskeeper Willie was really impressed with your coding for this pitchfork problem. This, of course, is a lie; he thinks "C++" is E. But no matter, he wants you to now write a program that will help him decide whether/how to "work" while at the school. More to the point, he wants the computer to tell him how to avoid work. So, you will write a program that will input various parameters and use them to tell Willie or anyone in his job what to do dependent on those input values.

Specifications: Your program should first prompt for and input the user's name (no whitespace in the name!) to be used in at least one subsequent prompt, and for the final output. It should then prompt for and read in information to make the correct recommendation to the user about how he/she should behave according to the following:

  1. The work recommendation will depend on the user's motivation, indicated by levels: a, b, c, d, and e. If motivation is at level e (which stands for "elevated slothfulness"), then the recommendation should be "stay in bed and skip work".

  2. If the motivation is input as d (standing for "don't plan on work from me"), then the user is recommended to

    • "hide in the tool shed" if it rained the night before

    • "hide in the hedge" if it didn't rain the night before

  3. If the motivation level input by the user is c (c is for "can't get good help no more!"), then

    • "lean on a rake" should be the recommendation if it rained less than or equal to 1.5 inches, and

    • "lean on a broom" (presumably inside) if it rained more than that

  4. If the user has b ("basically good worker") level motivation, then the recommendation is to:

    • "get on hands and knees and scrub floor" if either the number of children present is less than the number of adults present, OR if Superintendent Chalmers is present.

    • "mop the floor" otherwise

  5. An a-level motivation is truly impressive! (an excellent worker) If that is the input value, then

    • if the user has between and including 5 and 10 gals of gas and it rained less than 1/2 inch the night before, they should "mow the grass"

    • if they have more than 10 gal of gas and it rained less than 1/2 inch, they should "get on the tractor and do laps around the school" (looking really busy!)

    • and assuming less than 1/2 inch rain and less than 5 gal of gas, they should "go get more gas"

    • if it rained more than a 1/2 inch,

      • having less than 5 gal of gas, they should "burn old text books from the 1940's"

      • otherwise, "use that gas to clean the bathrooms"

      • in any other case, they should "write c++ programs".

In the preceding descriptions, you will need to prompt for and input information. But you must only prompt and input if the information is needed. Furthermore, in some cases, there is more than one way to input that information. In order for the graders' scripts for grading to run correctly, you must do this in the right way. So, be sure to understand:

  • input only if you need the information.

  • considering case 4 above, first prompt for and read in whether or not Chalmers is present, and then the number of people if necessary at that point.

  • to know if Chalmers is present, prompt for and input 'y' or 'n', a character to determine this factoid.

  • if you need to know if the number of children present is less than the number of adults, you must first input the number of children, then the number of adults, and the use math....like subtraction.

  • prompt for and input the inches of rain, even if you only need to know whether or not it rained. If you need to know both rain and gas, prompt for rain first. note: zero inches of rain means it didn't rain.

  • prompt for and input the number of gallons of gas if needed.

Very Important: Now that you know how to use sentinel loops (well, that's a hint), you are expected to validate any user input that is validatable1. Any numeric values input need to be checked for validity and reasonableness. For example, if you input someone's age, a negative value or a value over, say, 120, is not valid and should be re-prompted. Some inputs are not validatable - such as names. In most cases, you will have to choose reasonable values for validity. I know some of you will ask us questions about things like, "what's a maximum amount of rain in one night?" Please don't. Come up with a reasonable number on your own. (In one night, I think it probably can't rain more than 50 inches. We'll give you that one. Gas on hand? ... Willy could have a 500 gal tank in the shed. We'll give you that one too.)

As usual, make your output user-friendly. Write your code as efficiently as possible: meaning it should not do anything unnecessarily. Be sure to use constants where appropriate.

Remember: When writing your code, be sure to:

  • Declare your variables with the APPROPRIATE type.

  • Use meaningful variable names.

  • Use proper spacing for indentations.

  • Use constant declarations where appropriate....there are a lot of them in this assignment!

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

1Validatable is not a word. But I think you can figure out its meaning.