Activity: Height & Weight (C++)

This activity will provide you and your partner with experience in using C++. At the end of this activity, you will…

  • Be familiar with the standard I/O mechanisms in C++.
  • Be able to construct a simple arithmetic expression in C++.
  • Be able to document a C++ program using comments.

The Problem

Suppose your doctor needed a computer program to easily convert patient heights and weights into alternative units. The mathematics behind these conversions is well known and can easily be performed with a computer. If we limit ourselves to units of inches and meters (for height) and pounds and kilograms (for weight) we would need to know the following equivalencies:

1 inch = 0.0254 meters

and

1 pound = 0.45359237 kilograms

The Assignment

Given the previous discussion, suppose we were given the following algorithm and were asked to translate it into a C++ program:

algorithm

Use the above algorithm to create the corresponding C++ program. Remember from our in-class discussion that the basic I/O mechanisms in C++ are as follows:

    • cout is used to perform output to the screen (standard output)
    • cin is used to input the value typed by the user (standard input)

The multiplication operator is * (also known as an asterisk). Note that the algorithm does NOT have steps for declaring variables – you WILL need to declare five variables in your program (one string and four double variables). NOTE: You will need to include the <string> library in order to use the string type.

Open the C++ compiler and create a new program. Don’t forget to add one comment above or next to each C++ statement (those lines of code ending in a semicolon). These simple comments function as documentation for the program. Your comments should describe, in English, what that step is doing. Follow the other C++ Coding Guidelines as well.

When you have completed the program, show it to the instructor.