Question
PROBLEM Your grandmother has just come back from the doctors office and is confused about all the numbers that were used to evaluate her health.
PROBLEM Your grandmother has just come back from the doctors office and is confused about all the numbers that were used to evaluate her health. The nurse weighed her, took her blood pressure, noted her cholesterol from her lab work, told her to sit down, and said that the doctor would be in shortly. After half an hour the doctor came in, looked at her chart, smiled, and said that she was fine. In looking over the report they gave your grandmother, you realize that there could be a market for a program to explain this information to medical patients. You have a project due in your software engineering class, so you decide to write a program to do exactly that.
Before you can state the input and output from this program, you need to do some research on the Web. You find that there are two important parts to a cholesterol reading: HDL (good) and LDL (bad). The ratio of the two is also important. You find several references that provide interpretations for a range of input values. The interpretation of your weight is dependent on the ratio of our weight to your size as represented by the body mass index (BMI). Great, you already have a program to calculate the BMI! Blood pressure is made up of two values: systolic and diastolic. When talking about blood pressure, the readings are usually given as something over something, such as 120/80. The first value is the systolic pressure, and the second value is the diastolic pressure. Now you have enough information to determine the input for your program.
INPUT Patients name, HDL, LDL, weight in pounds, height in inches, systolic pressure, and diastolic pressure.
OUTPUT Patients name and an interpretation of the cholesterol, weight, and blood pressure readings are written on file Profile.
DISCUSSION The decomposition of this problem into tasks is very straightforward. The data values are prompted for, entered, and evaluated. The only question is whether to enter the data all at once and evaluate it or have each evaluation module enter its own data. The principle of information hiding suggests that we embed the data gathering within the functions that evaluate the data.
Here are the interpretations you found on the Internet concerning cholesterol.
HDL Interpretation
<40 Too low
>=40and <60 Is okay
>=60 Excellent
LDL Interpretation
<100 Optimal
>=100 and <130 Near optimal
>=130 and <160 Borderline high
>=160 and <190 High
>=190 Very high
Fortunately, you already have a BMI calculator that can simply be turned into a function (with the food suggestions removed). What about blood pressure readings? Again, here is what you found on the Internet concerning blood pressure readings.
Systolic Interpretation
< 120 Optimal
< 130 Normal
< 140 Normal high
< 160 Stage 1 hypertension
< 180 Stage 2 hypertension
>= 180 Stage 3 hypertension
Diastolic Interpretation
< 80 Optimal
< 85 Normal
< 90 High normal
< 100 Stage 1 hypertension
<110 Stage 2 hypertension
>= 110 Stage 3 hypertension
Main Level 0 |
Open output file If output file not opened ok Write error message Return1 Get name Evaluate Cholesterol Evaluate BMI Evaluate blood pressure Close output file |
Get name Out: Function value Level 1
|
Prompt for first name Get first name Prompt for last name Get last name Prompt for middle initial Get middle initial Return first + +middle +. + last |
Evaluate Cholesterol (Inout; healthProfile; In; name) |
Prompt for names input Get data Evaluate input according to charts Print message |
Name has been added to the parameter list so that the user can prompt for the specific patients data. The first two lines and the last line can be directly translated into C++.
Evaluate Input (In: HDL, LDL) |
If (HDL < 40) Print on healthProfile HDL is too low else if (HDL < 60) Print on healthProfile HDL is okay else Print on healthProfile HDL is excellent
If (LDL < 100) Print on healthProfile LDL is optimal Else if (LDL < 130) Print on healthProfile LDL is near optimal Else if (LDL < 160) Print on healthProfile LDL is borderline high Else if (LDL < 190) Print on healthProfile LDL is high Else Print o healthProfile LDL is very high
If (ratio < 3.22) Print on healthProfile Ratio of LDL to HDL is good Else Print on healthProfile Ratio of LDL to HDL is not good |
C++
Which modules should be functions and which should be coded inline? GetName should obviously be a value-returning function; EvaluateCholesterol, EvaluateBloodPressure clearly should be void functions. The question is whether the EvaluateInput modules should be coded as separate functions. If we were coding this problem in a language that allowed us to embed a function within a function, good style would suggest that we make the EvaluateInput modules separate functions. However, C++ does not allow nested functioning. The EvaluateInput modules would have to be coded at the same level as the functions that call them. Thus, these modules should be coded in line. Another reason for doing so is that EvaluateCholesterol, EvaluateBMI, and EvaluateBloodPressure are tightly knit functions with a clearly stated purpose and interface.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started