Due 18 May, 2005
Assignment 2 is similar to Assignment 1, but the functionality of the program now includes validation of inputs, and repetative interaction with the user, for as long as the user desires. Additionally, there is a non-functional requirement for this assignment. The program must be written to take advantage of functional abstraction. These requirements will be clarified in the Requirements section.
Write a C++ program that prompts for and reads a patient's name, weight in pounds, and height in feet and inches, and then calculates and displays the patient's name, mass in kilograms, height in meters, and Body Mass Index (BMI), and then repeats this process any number of times. For example:
What is the patient's name? ArnoldaIn the example above, the italic or slanted text represents input typed by a user of the program. The rest of the text represents the prompts and other output of the program.
What is the patient's weight in pounds? 100
What is the patient's height in feet and inches? 5 1
Arnolda's weight is about 45.36 kilograms.
Arnolda's height is about 1.5494 meters.
Arnolda's BMI is approximately 18.895 .
Would you like to calculate the BMI for another patient (y/n)? y
What is the patient's name? Jason
What is the patient's weight in pounds? 0.0
I'm sorry, that is not a valid value for this item. Please try again. What is the patient's weight in pounds? 120
What is the patient's height in feet and inches? 5 13
I'm sorry, that is not a valid value for this item. Please try again. What is the patient's height in feet and inches? -3 7
I'm sorry, that is not a valid value for this item. Please try again. What is the patient's height in feet and inches? 5 7
Jason's weight is about 54.432 kilograms.
Jason's height is about 1.7018 meters.
Jason's BMI is approximately 18.7948 .
Would you like to calculate the BMI for another patient (y/n)? z
I'm sorry, that is not a valid value for this item.
Would you like to calculate the BMI for another patient (y/n)? n
Functional Requirements
Non-functional Requirements
A person's Body Mass Index (BMI) is defined to be the person's
mass m in kilograms divided by the square of the person's
height h in meters. In C++ this calculation would be
written as m / (h * h).
There are still a few corners of the world where the old English system of measures remains in use. In the United States, the Omnibus Trade and Competitiveness Act of 1988 declared the International System of Units (SI) to be the preferred system for trade and commerce, but many citizens continue to think in terms of pounds and inches. This program accomodates them.
One pound corresponds to approximately 453.6 grams, which is .4536 kilograms. One inch corresponds to 2.54 centimeters, which is .0254 meters. One foot equals twelve inches. Hence: