CPTR 124 Fundamentals of Programming


This lab introduces conditional execution.
  1. Familiarize yourself with the assignment

    Read over the complete lab before you begin writing your program.

  2. Housekeeping

    You will write two separate C++ programs. Name your source files maxof5.cpp and bmi.cpp.

  3. What to do

    Write C++ programs to solve the following two problems:

    1. Maximum of Five

      Write a program that allows the user to enter in exactly five integer values. The program then should print the largest of the five values entered. A sample run is shown here:

      Please enter five integer values Number 1: 20 Number 2: -1 Number 3: 6 Number 4: 31 Number 5: 19 The maximum is 31

      (The 20, –1, 6, 31, and 19 correspond to user input; the program is responsible for the rest of the output.)

      Even if there is a tie for the maximum value, just print the maximum once.

      Hint: You can use fairly complicated conditional expressions involving &&'s, etc., or you can use very simple conditional expressions. If want to implement the simpler logic, you can introduce an additional variable and use four very simple, sequential if statements. The tradeoff of an extra variable for the greatly simplified logic is a good one.

    2. Body Mass Index

      The body mass index (BMI) is a measure of relative weight. It takes into account both height and weight in an attempt to determine if a person is underweight, normal weight, or overweight. BMI often is used to estimate a person's risk of health problems. BMI is easy to compute:

      BMI = mass/height^2

      where mass is a person's mass in kilograms, and height is the person's height in meters.

      Write a program that requests a person's weight in pounds and height in feet and inches. The program then should print the person's BMI and then report the person's classification according to the following table:

      BMI Range Classification
      BMI < 18.5 underweight
      18.5 ≤ BMI < 25 normal weight
      25 ≤ BMI < 30 overweight
      BMI ≥ 30 obese

      Note that you must convert pounds to kilograms and feet and inches to meters before performing the computation. 1 pound = 0.454 kilograms, 12 inches = 1 foot, and 1 inch = 0.0254 meters.

      Please enter your weight in pounds: 150 Next, enter your height in feet and inches . . . Enter feet: 5 Enter inches: 10 Your BMI is 21.541879818453516 Your classification is NORMAL WEIGHT

      Your output should be formatted to look like the sample run above.

  4. Check out

    I will review your lab with you before you leave. Be prepared to answer questions about any parts of your program. After you have been checked out, please submit your two C++ source files (the maxof5.cpp and bmi.cpp files) to http://eclass.e.southern.edu.