Question
c++ Scope and Lifetime //****************************************************************** // Profile Program // This program inputs a name, weight, height, blood pressure // readings, and cholesterol values. Appropriate health
c++ Scope and Lifetime
//****************************************************************** // Profile Program // This program inputs a name, weight, height, blood pressure // readings, and cholesterol values. Appropriate health messages // are written for each of the input values on file healthProfile. //******************************************************************
#include
using namespace std;
// Function prototypes string Name(); // This function inputs a name and returns it in first, // middle initial, and last order
void EvaluateCholesterol(ofstream& healthProfile, string name); // This function inputs HDL (good cholesterol) and LDL (bad // cholesterol) and prints out a health message based on their // values on file healthProfile. // Pre: Input file has been successfully opened
void EvaluateBMI(ofstream& healthProfile, string name); // This function inputs weight in pounds and height in inches and // calculates the body mass index (BMI prints a health message // based on the BMI. Input in English weights. // Pre: Input file has been successfully opened
void EvaluateBloodPressure(ofstream& healthProfile, string name); // This function gets blood pressure readings (systolic/diastolic) // and prints out a health message based on their values // on file healthProfile. // Pre: Input file has been successfully opened
int main() { // Declare and open the output file ofstream healthProfile; healthProfile.open("Profile"); string name; name = Name();
// Write patient's name on output file healthProfile
// Evaluate the patient's statistics EvaluateCholesterol(healthProfile, name); EvaluateBMI(healthProfile, name); EvaluateBloodPressure(healthProfile, name); healthProfile
healthProfile.close(); system("PAUSE"); return 0; }
//******************************************************************
string Name() // This function inputs a name and returns it in first, // middle initial, and last order { // Declare the patient's name string firstName; string lastName; char middleInitial;
// Prompt for and enter the patient's name cout > firstName; cout > lastName; cout > middleInitial; return firstName + ' ' + middleInitial + ". " + lastName; }
//******************************************************************
void EvaluateCholesterol(ofstream& healthProfile, string name) // This function inputs HDL (good cholesterol) and LDL (bad // cholesterol) and prints out a health message based on their // values on file healthProfile. { int HDL; int LDL;
// Prompt for and enter HDL and LDL cout > HDL; cout > LDL; float ratio = (float)HDL / (float)LDL; // Calculate ratio of HDL to LDL
healthProfile
// Print message based on HDL value if (HDL
if (ratio > 0.3) healthProfile
//******************************************************************
void EvaluateBMI(ofstream& healthProfile, string name) // This function inputs weight in pounds and height in inches and // calculates the body mass index Input in English weights. { const int BMI_CONSTANT = 703; // Constant in English formula int pounds; int inches;
// Enter the patient's weight and height cout > pounds; cout > inches; int bodyMassIndex = pounds * BMI_CONSTANT / (inches * inches);
healthProfile
// Print interpretation of BMI if (bodyMassIndex
//******************************************************************
void EvaluateBloodPressure(ofstream& healthProfile, string name) // This function gets blood pressure readings (systolic/diastolic) // and prints out a health message based on their values // on file healthProfile. { // Declare the blood pressure readings int systolic; int diastolic;
// Enter the patient's blood pressure readings cout > systolic; cout > diastolic;
// Print interpretation of systolic reading healthProfile
// Print interpretation of diastolic reading if (diastolic
} }
Exercise 1: Compile and run program Prorile (prorile.cpp), using data of your choice. Exercise 2: The tables used in program Health were not consistent in form because they came from different sources; tha is, some were written in a form that could be directly coded in C++ and some were not. For example the cholesterol charts used "and." In coding them, they all had to be changed into a cascading if form. Here are the tables themselves in that form. BMI High-Risk IndicatorStep 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