• No se han encontrado resultados

4. PROPUESTA DE TRABAJO

4.6 Estabilidad de las paredes de la excavación

/* in */ float width); {

return length * 1.6 * width * 1.6; }

11.

bool Exahausted (/* in */ int filmRolls) {

static int total = 0; total = total + filmRolls; if (total > 1000) { total = 0; return true; } else return false; }

12.

string MonthAbbrev (/* in */ int month) {

if (month == 12) return "Dec"; else if (month == 11) return "Nov"; else if (month == 10) return "Oct"; else if (month == 9) return "Sep"; else if (month == 8) return "Aug"; else if (month == 7) return "Jul"; else if (month == 6) return "Jun"; else if (month == 5) return "May"; else if (month == 4) return "Apr"; else if (month == 3) return "Mar"; else if (month == 2) return "Feb"; else return "Jan";

}

13.

string MonthAbbrev (/* in */ int month) {

if (month == 12) return "Dec"; else if (month == 11) return "Nov"; else if (month == 10) return "Oct"; else if (month == 9) return "Sep"; else if (month == 8) return "Aug"; else if (month == 7) return "Jul"; else if (month == 6) return "Jun"; else if (month == 5) return "May"; else if (month == 4) return "Apr";

else if (month == 3) return "Mar"; else if (month == 2) return "Feb"; else if (month == 1) return "Jan"; else return "Inv";

}

14.

float RunningAvg (/* in */ float value) {

static float total = 0.0; static int count = 0; total = total + value; count++;

return total/float(count); }

Chaper 8

Case Study Follow-Up Exercises

1.

Evaluate BloodPressure(Inout: healthProfile; In: name)

Prompt for name’s input

Get data

Evaluate input according to charts and print message

Evaluate Input and Print Level 2

if (systolic < 120)

Print on healthProfile “ Systolic reading is optimal” else if (systolic < 130)

Print on healthProfile “ Systolic reading is normal” else if (systolic < 140)

Print on healthProfile “ Systolic reading is high normal” else if (systolic < 160)

Print on healthProfile “ Systolic indicates hypertension Stage 1” else if (systolic < 180)

Print on healthProfile “ Systolic indicates hypertension Stage 2” else

Print on healthProfile “ Systolic indicates hypertension Stage 3” if (diastolic < 80)

Print on healthProfile “ Diastolic reading is optimal” else if (diastolic < 85)

Print on healthProfile “ Diastolic reading is normal” else if (diastolic < 90)

else if (diastolic < 100)

Print on healthProfile “ Diastolic indicates hypertension Stage 1” else if (diastolic < 110)

Print on healthProfile “ Diastolic indicates hypertension Stage 2” else

Print on healthProfile “ Diastolic indicates hypertension Stage 3”

2.

//****************************************************************** // EvaluateBloodPressure Driver program

// This program provides an environment for testing the

// EvaluateBloodPressure function in isolation from the Profile // program

//****************************************************************** #include <iostream>

#include <fstream> using namespace std;

void EvaluateBloodPressure(ofstream&, string); int main()

{

ofstream healthProfile;

healthProfile.open("ProfileBP"); string name = "John J. Smith";

for (int test = 1; test <= 12; test++)

EvaluateBloodPressure(healthProfile, name); healthProfile.close(); return 0; } //****************************************************************** void EvaluateBloodPressure

( /* inout */ ofstream& healthProfile, // Output file /* in */ string name ) // Patient's name {

// Declare the health statistics int systolic;

int diastolic;

// Enter the patient's health statistics

cout << "Enter the systolic blood pressure reading for" << name << ": ";

cin >> systolic;

cout << "Enter the diastolic blood pressure reading for " << name<< ": ";

cin >> diastolic;

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;

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;

}

3.

//****************************************************************** // Profile Program

// This program inputs a name, weight, height, blood pressure // readings, and cholesterol values. If an input value is // negative, an error message is written. Appropriate health // messages are written for each of the input values.

#include <fstream> #include <iostream> #include <string> using namespace std; string Name();

void EvaluateCholesterol(ofstream& healthProfile, string name, bool& dataOK);

void EvaluateBMI(ofstream& healthProfile, string name, bool& dataOK);

void EvaluateBloodPressure(ofstream& healthProfile, string name, bool& dataOK);

int main() {

// Declare and open the output file ofstream healthProfile;

healthProfile.open("Profile"); string name;

bool dataOK; name = Name();

// Evaluate the patient's statistics

healthProfile << "Patient's name " << name << endl; EvaluateCholesterol(healthProfile, name, dataOK); EvaluateBMI(healthProfile, name, dataOK);

EvaluateBloodPressure(healthProfile, name, dataOK); healthProfile << endl; healthProfile.close(); return 0; } //****************************************************************** // Name function

// This function inputs a name and returns it in first, // middle initial, and last order.

//****************************************************************** string Name()

{

// Declare the patient's name string firstName;

string lastName; char middleInitial;

// 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; }

//****************************************************************** // Cholesterol function

// This function inputs HDL (good cholesterol) and LDL (bad // cholesterol) and prints out a health message based on their // values on file healthProfile.

//****************************************************************** void EvaluateCholesterol

( /* inout */ ofstream& healthProfile, // Output file /* in */ string name, // Patient's name /* out */ bool& dataOK)

{

int HDL; int LDL;

cout << "Enter HDL for " << name << ": "; cin >> HDL;

cout << "Enter LDL for " << name << ": "; cin >> LDL;

dataOK = HDL > 0 && HDL > 0; if ( !dataOK )

cout << " Cholesterol data must be positive; test aborted. "; else

{

float ratio = LDL/HDL; // Calculate ratio of LDL to HDD healthProfile << "Cholesterol Profile " << endl;

// Print message based on HDL value if (HDL < 40)

healthProfile << " HDL is too low" << endl; else if (HDL < 60)

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;

} }

//****************************************************************** // BMI Function

// 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.

//****************************************************************** void EvaluateBMI

( /* inout */ ofstream& healthProfile, // Output file /* in */ string name, // Patient's name /* out */ bool& dataOK)

{

const int BMI_CONSTANT = 703; // Constant in English formula float pounds;

float inches;

cout << "Enter the weight in pounds for " << name << ": "; cin >> pounds;

cout << "Enter the height in inches for " << name << ": "; cin >> inches;

dataOK = pounds > 0 && inches > 0; if ( !dataOK)

cout << " BMI data must be positive; test aborted. "; else

{

float bodyMassIndex = pounds * BMI_CONSTANT / (inches * inches);

healthProfile << "Body Mass Index Profile" << endl; // Print health message based on bodyMassIndex

healthProfile << " Body mass index is " << bodyMassIndex << ". " << endl;

healthProfile << " Interpretation of BMI " << endl; if (bodyMassIndex < 18.5)

healthProfile << " Underweight: BMI is too low" << endl;

else if (bodyMassIndex < 24.9)

healthProfile << " Normal: BMI is average" << endl; else if (bodyMassIndex < 29.9)

healthProfile << " Overweight: BMI is too high" << endl;

else

healthProfile << " Obese: BMI is dangerously high" << endl;

} }

//****************************************************************** // Blood Pressure function

// This function gets blood pressure readings (systolic/diastolic) // and prints out a health message based on their values

// in file healthProfile.

//****************************************************************** void EvaluateBloodPressure

( /* inout */ ofstream& healthProfile, // Output file /* in */ string name, // Patient's name /* out */ bool& dataOK)

{

// Declare the health statistics int systolic;

int diastolic;

// Enter the patient's health statistics

cout << "Enter the systolic blood pressure reading for " << name << ": ";

cin >> systolic;

cout << "Enter the diastolic blood pressure reading for " << name << ": ";

cin >> diastolic;

dataOK = systolic > 0 && diastolic > 0; if ( !dataOK )

cout << " Blood pressure data must be positive;" << " test aborted. ";

else {

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;

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;

} }

Documento similar