Assignment 05

Due: Tuesday, Oct. 3, 2017 at noon 100 pts

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 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! 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 5 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.

3. Nap Time!!

4. Caloric Intake

5. Quit

    1. When the user chooses option 1, the program should prompt for and read in the number of "legs" of the walk the user wishes to have. The output from the program will look like this:

      1. 25 R

      2. 49 L

      3. 99 L

      4. 35 R

      5. 23 L

      6. . . .

      7. total distance: 543 steps (step = pace)

      8. That is, your program will generate the requested number of legs of the walk, each leg will be assigned a random number of paces (that number above) between 20 and 120, inclusive, and a direction to turn next (that letter, R or L). All of these are chosen at random. The total number of steps is displayed.

  1. Option 2 chosen will trigger prompts for the user to input their current anxiety level (1 -> 10) and the day of the week (1 -> 7). From this information, the program will compute and output the number of pills the user should take that day1.

  2. If option 3 is chosen, your program is to refuse to do anything if both options 1 and 2 haven't yet been chosen during that run of the program. That is because the computations for option 3 require the information from options 1 and 2. Now, if options 1 and 2 have indeed been chosen, then your program code for option 3 starts by prompting the user for the number of hours they slept the previous night. This information, along with the computed values from options 1 and 2, will be used to compute and output the number of minutes you may nap for.

  3. Choosing option 4 will initiate prompts for body weight, body height, and room temperature. From this, the code should compute and output caloric intake allowable at that moment.

  4. Choosing quit will terminate the program....of course.

Details: First, you are required to use the switch statement for handling the options chosen from the menu. Secondly, you will use functions for the program and they are laid out here:

  1. A function that does nothing more than displaying the greeting for the program. It should have no parameters and return nothing.

  2. A function to display the menu and reads in a response (character) from the user and returns it to the main function. It should NOT "input cleanse"; any response from the user should be handled by the switch in main.

  3. A function that will prompt for and read in a positive integer for the number of legs of the walk. This (cleansed) value is returned to the calling function (presumably main).

  4. A function to which you pass the value returned by the preceding function, and it will output the pattern indicated above and return nothing. the total distance walked.

  5. A function that prompts for and reads in anxiety level (valid input is 1 -> 10) and returns it.

  6. A function that prompts for and reads in the day (valid input is 1 -> 7) and returns it.

  7. A function to which you pass the two values above (anxiety and day) and it returns the number of pills the user should take according to

      1. number of pills = anxiety - day if this is non-negative; 0 otherwise.

  8. A function to which you pass the number of pills and it will output it to the screen.

  9. A function that prompts for and reads in the number of hours slept the previous night.

  10. A function to which you pass the number of hours slept, the distance walked as determined by option 1, and the number of pills as determined by option 2. It will return the number of minutes for a nap according to

      1. minutes = hrs slept + dist walked / number of pills(if 0, divide by 1)

2. Your Medications

1. Taking a Walk!

Health-o-Matic Options

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

Background: In this assignment, you are going to write a menu driven program to help Hans out with his "health management issues". Yep, indeed, it's no longer enough to just take care of yourself by eating right and getting enough exercise. You had better spend a lot of money, have a personal health trainer, a membership to a gym, take way too many pills and subscribe to every hair-brained self-help scheme alive. But I digress. This program will present the user with several options concerned with improving health in varied manners. The user will choose an option, following instructions about prompted information, receive the intended recommendation, and then have the menu presented to them once again. Of course, the user can quit at any point. Your code will be implemented using functions, a topic we started not long ago. Now you will have your practice with them.Specifications: You are to use functions in the program. In fact, below is a description of the functions we want you to use. Your program will present a greeting and menu of options to the user. It should look something like this:

  1. A function to which you pass the value from #13 above and it will output it.

For the foregoing functions, if they are to prompt and input values, they should "cleanse input" with reasonable limits. For example, prompting for a weight should reject responses that are non-positive and those over 500lbs....well, 800lbs.

When you submit: As usual, when you submit, you are all to enter the same information so as not to drive the graders crazy. Following these steps:

  • choose option 3 (better get an error message!)

  • choose option 4 (get an error message)

  • choose option 1 and enter 5 (5 legs for the walk)

  • choose option 3 (again, error!)

  • choose option 2 and enter anxiety of 4 and day 6

  • choose option 3 and enter 4 hrs sleep

  • choose option 4 and enter 450 lbs, 66 inches, and 98.9 F.

  • quit

And as always, if you have questions concerning this programming assignment, don't hesitate to consult your instructor

1This assumes you take pills. Given the state of American health today, it's a pretty fair assumption. If you don't take pills, just visit the doc's office. You will be soon afterwards. Furthermore, Dr. Nick hasn't yet worked out how this formulation applies to different medications. So, for now, trust that this recommendation applies to every medication! Ahhh, the miracles of modern medical technology.

  1. A function to output the number of minutes for a nap. It will have one parameter.

  2. Three functions, each to prompt for and read in user's weight, height, and room temp and return those values.

  3. A function to which the preceding three values are passed (along with the distance walked) and it will compute and return calories according to the formula

      1. cals = 6 * wt + 2 * ht + 1/(temp) + dist. walked