//****************************************************************** // 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. // To save space, we omit from each function the precondition // comments that document the assumptions made about valid input // parameter data. These would be included in a program intended // for actual use. //****************************************************************** #include #include #include using namespace std; // Function prototypes string Name(); void EvaluateCholesterol(ofstream& healthProfile, string name); void EvaluateBMI( ofstream& healthProfile, string name); void EvaluateBloodPressure( ofstream& healthProfile, string name); 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 << "Patient's name " << name << endl; // Evaluate the patient's statistics EvaluateCholesterol(healthProfile, name); EvaluateBMI(healthProfile, name); EvaluateBloodPressure(healthProfile, name); healthProfile << endl; healthProfile.close(); return 0; } //****************************************************************** string Name() // Name function // This function inputs a name and returns it in first, // middle initial, and last order // Postcondition: // Return value is the string composed of of the first name, // blank, middle initial, period, blank, last name { // Declare the patient's name string firstName; string lastName; char middleInitial; // Prompt for and enter the patient's name cout << "Enter the patient's first name: "; cin >> firstName; cout << "Enter the patient's last name: "; cin >> lastName; cout << "Enter the patient's middle initial: "; cin >> middleInitial; return firstName + ' ' + middleInitial + ". " + lastName; } //****************************************************************** void EvaluateCholesterol ( /* inout */ ofstream& healthProfile, // Output file /* in */ string name ) // Patient's name // This function inputs HDL (good cholesterol) and LDL (bad // cholesterol) and prints out a health message based on their // values on file healthProfile. // Precondition: // Input file has been successfully opened // Postcondition: // Appropriate health messages for the input values of // HDL, LDL, and their ratio have been printed on file // healthProfile. { int HDL; int LDL; // Prompt for and enter HDL and LDL cout << "Enter HDL for " << name << ": "; cin >> HDL; cout << "Enter LDL for " << name << ": "; cin >> LDL; float ratio = LDL/HDL; // Calculate ratio of LDL to HDL healthProfile << "Cholesterol Profile " << endl; // Print message based on HDL value if (HDL < 40) healthProfile << " HDL is too low" << endl; else if (HDL < 60) healthProfile << " HDL is okay" << endl; else healthProfile << " HDL is excellent" << endl; // Print message based on LDL value if (LDL < 100) healthProfile << " LDL is optimal" << endl; else if (LDL < 130) healthProfile << " LDL is near optimal" << endl; else if (LDL < 160) healthProfile << " LDL is borderline high" << endl; else if (LDL < 190) healthProfile << " LDL is high" << endl; else healthProfile << " LDL is very high" << endl; if (ratio < 3.22) healthProfile << " Ratio of LDL to HDL is good" << endl; else healthProfile << " Ratio of LDL to HDL is not good" << endl; } //****************************************************************** void EvaluateBMI ( /* inout */ ofstream& healthProfile, // Output file /* in */ string name ) // Patient's 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. // Precondition: // Input file has been successfully opened // Postcondition: // Appropriate health messages for the BMI based on input values // of weight and height have been printed on file healthProfile { const int BMI_CONSTANT = 703; // Constant in English formula float pounds; float inches; // Enter the patient's weight and height cout << "Enter the weight in pounds for " << name << ": "; cin >> pounds; cout << "Enter the height in inches for " << name << ": "; cin >> inches; float bodyMassIndex = pounds * BMI_CONSTANT / (inches * inches); healthProfile << "Body Mass Index Profile" << endl; // Print bodyMassIndex healthProfile << " Body mass index is " << bodyMassIndex << ". " << endl; healthProfile << " Interpretation of BMI " << endl; // Print interpretation of BMI if (bodyMassIndex <20) healthProfile << " Underweight: BMI is too low" << endl; else if (bodyMassIndex <=25) healthProfile << " Normal: BMI is average" << endl; else if (bodyMassIndex <= 30) healthProfile << " Overweight: BMI is too high" << endl; else healthProfile << " Obese: BMI is dangerously high" << endl; } //****************************************************************** void EvaluateBloodPressure ( /* inout */ ofstream& healthProfile, // Output file /* in */ string name ) // Patient's name // This function gets blood pressure readings (systolic/diastolic) // and prints out a health message based on their values // on file healthProfile. // Precondition: // Input file has been successfully opened // Postcondition: // Appropriate health messages for the blood pressure readings, // based on input values of systolic and diastolic pressure have // been printed on file healthProfile { // Declare the blood pressure readings int systolic; int diastolic; // Enter the patient's blood pressure readings cout << "Enter the systolic blood pressure reading for" << name << ": "; cin >> systolic; cout << "Enter the diastolic blood pressure reading for " << name << ": "; cin >> diastolic; // Print interpretation of systolic reading healthProfile << "Blood Pressure Profile " << endl; if (systolic < 120) healthProfile << " Systolic reading is optimal" << endl; else if (systolic < 130) healthProfile << " Systolic reading is normal" << endl; else if (systolic < 140) healthProfile << " Systolic reading is high normal" << endl; else if (systolic < 160) healthProfile << " Systolic indicates hypertension Stage 1" << endl; else if (systolic < 180) healthProfile << " Systolic indicates hypertension Stage 2" << endl; else healthProfile << " Systolic indicates hypertension Stage 3" << endl; // Print interpretation of diastolic reading if (diastolic < 80) healthProfile << " Diastolic reading is optimal" << endl; else if (diastolic < 85) healthProfile << " Diastolic reading is normal" << endl; else if (diastolic < 90) healthProfile << " Diastolic reading is high normal" << endl; else if (diastolic < 100) healthProfile << " Diastolic indicates hypertension Stage 1" << endl; else if (diastolic < 110) healthProfile << " Diastolic indicates hypertension Stage 2" << endl; else healthProfile << " Diastolic indicates hypertension Stage 3" << endl; }