Wednesday, October 19, 2011

Exam #1 pretest comments -
     part the second

These are the solutions to the last two programming problems at the end of Monday night's pretest.

Instead of responding to each student individually, I am providing the source code solutions. Please be sure to review and understand all of these solutions.

  1. Write a program that displays the following table. Note that 1kilo is equal to 2.2 pounds.

       Kilograms   Pounds
       10                     22.0
       30                     66.0
       ...
       90                    198.0
       110                   242.0

Question 10 source code

Note that to obtain the desired output for the kilograms to pounds table you needed to use the escape sequence for tabs (\t) and also to use setprecision and fixed in the output stream (both found in the iomanip header file).

  1. Write a program that calculates a random number from 1 to 10. Ask the user to guess the number. If the user guesses correctly, display a congratulatory message. If the user displays an incorrect answer, give the user two more tries. If after three attempts the user still has not guessed the number, display a message to that effect and terminate the program.

Question 11 source code