Assignment 02

Due: Thursday, Sept. 8, 2011, 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, 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 2 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: Groundskeeper Willie, keeper of the grounds for Springfield Elementary, quite often has to dispose of dead 'possums. But he always has trouble choosing the instrument to use to transport them (to the principal's car, of course). He normally picks up the 'possum with one of his many pitchforks. He has several, like 12 of them, all with different length handles. They range in length from short to longer to even longer; then there's really long. He wants you to write a computer program that will calculate handle length of the appropriate pitchfork, and then tell him which fork to use. How he chooses the tool-o-choice is dependent on the following:

  • the weight of the 'possum, wt: a real number that ranges from 2.7 (juvenile 'possums) to 45.5 (el mondo 'possums)

  • the stink factor of the carcass, SF: an integer from 1 to 10 (really stinky)

  • the length of the animal's tail, L: a real number between 4.5 and 15

  • the International Dead Infectious Opossum Threshold Score, IDIOTS: currently set by the Dead Opposum Standards Committee to be 8.

  • barometric pressure, BP (well, that's logical)

The formula for calculating the length of the fork handle is as follows:

length = (SF/IDIOTS) x (3L + wt) + 30(SF/BP)

Once length is computed, your program will need to figure out which of his 12 forks he needs to use. They are numbered 1 - 12 and used in the following way:

  • fork #1 has handle 15" long and is used when the job requires a handle length between 10 and 19.9 inches

  • fork #2 has handle 25" long and is used when the job requires a handle length between 20 and 29.9 inches

  • fork #3 has handle 35" long and is used when the job requires a handle length between 30 and 39.9 inches

  • etc

So, you see, if you compute the handle length to be, say, 48.2, then that indexes to 4.

So, you will begin your program by greeting the user. Then, you need to prompt for and read in the user input for the calculation(s). After that, you will output an echo of the input values, the calculated handle length, and then the fork number. You need to make your output "user friendly". Output such as

6

is not user-friendly. Notice that there is no label on the number, no words explaining what has been done, etc. Here's a better output format:

For the following inputs: wt: xxxx bar pressure: yyy stink: zz tail: vv handle length is: wwww and fork number is: r

You get the idea.

NOTE: You are NOT to use decision-branching in the solution. That is, you may NOT use the if-else or the switch-case statements.

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.

  • 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 this, and all subsequent programs for this class, cssubmit will compile and run (assuming it compiles) your program during the submission process. Thus, when you submit, you will have to enter inputs as a user of the program. Now, in order to make the output uniform for the grader and to keep her/him sane, ALL OF YOU will enter the same information. For this assignment, it is:

  • stink factor of 7

  • barometric pressure of 31

  • tail length of 9.5

  • wt of 28.2

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