Home

Background Information

Research Paper

Graphs

Charts and Statistics

Program

Program Code



#include < iostream.h >
#include < math.h >
#include < fstream.h >

int main()
{

//makes program refer to data file injury.dat
fstream InFile ("injury.dat",ios::in | ios::out); 

//declares variables
//variables input by user
double weight;     //weight input by user
double kg;	   //weight converted to kilograms
double feet;       //feet input by user
double inch;       //inches input by user
double height;     //total height in inches
double meter;      //converts height in inches to meters
double gender;        //gender input by user
double age;           //age input by user
double max_age;	   //maximum age for calculations, input by user
double min_age;	   //minimum age for calculations, input by user
double bmi;        //Body Mass Index = (wt/ht^2)
double max_bmi;    //maximum BMI for calculations, input by user
double min_bmi;    //minimum BMI for calculation, input by user
double userperc_bmi;  //percentage of people within BMI range
double userperc_age;  //percentage of people within age group

//variables from data file                               
const int count=303;	   //total number of patients in data file
double w[count];	   //weight from data file
double h[count]; 	   //height from data file, already in inches
double g[count];	   //gender from data file
double a[count];	   //age from data file
double type[count];	   //type of injury from data file
int c_type[count];	  //counts number of injuries (only types)
int c_bmi[count];		   //counts number of BMIs within range
int c_age[count];		   //counts number of ages within range
double bmi2;

//Explanation of program to user
cout<<"This program will determine which type of knee injury is most
likely to occur based on the information you enter and the statistical
information located in the data base.  "<< endl;
 //User inputs all information needed for calculation
cout<< "Are you a male or a female?"<< endl;
cout<< "Please enter 1 for male and 2 for female: ";
cin >>gender;
//prompts user for age
cout<< "How old are you? "; cin >>age;
//prompts user for height
cout<<"How tall are you in feet and inches?"<< endl;
cout<<"Feet: "; cin >>feet; cout<<"Inches: "; cin >>inch; //calculates height in inches height = ((feet*12) + inch); //converts height in inches to meter meter = (height *.0254); //prompts user for weight cout<<"Please enter your weight in pounds: "; cin>>weight; //converts weight from pounds to kilogram kg=(weight*0.45); //calculates a person's body mass index bmi = (kg/(meter*meter)); //prints out BMI cout << "Based on your height and weight, your Body Mass Index is " << bmi << "."<18.5) && (bmi <=24.9)) cout<< "This means you are of normal weight."<< endl; else if ((bmi>24.9) && (bmi <=29.9)) cout<< "This means you are overweight."<< endl; else if ((bmi >29.9) &&(bmi <=39.9)) cout<< "This means you are obese."<< endl; else if (bmi >39.9) cout<< "This means you are extremely obese."<< endl; //Prints out BMI chart so user can pick minimum and maximum BMI cout<< "\t\t Body Mass Index Chart"<< endl; cout<< "\t\tFrom:\tTo:\tBody Type"<< endl; cout<< "\t\t0\t18.5\tUnderweight"<< endl; cout<< "\t\t18.6\t24.9\tNormal Weight"<< endl; cout<< "\t\t25\t29.9\tOverweight"<< endl; cout<< "\t\t30\t39.9\tObese"<< endl; cout<< "\t\tGreater than 40\tExtremely Obese"<< endl; //prompts user for minimum and maximum BMI //these are the values that will be used to define the search cout<< "Please enter the minimum Body Mass Index for your search: "; cin >>min_bmi; cout<< "Please enter the maximum Body Mass Index for your search: "; cin >>max_bmi; //prints out the person age cout << "Your age is " << age << "."<< endl; //prompts user for minimum and maximum age //these values will be used to define the search cout << "Please enter the minimum age for your search: "; cin >> min_age; cout << "Please enter the maximum age for your search: "; cin >> max_age; //read data file using a for loop for(int i=0; i < count; i++) { //fills arrays with correct information InFile >>w[i]; InFile >>h[i]; InFile >>g[i]; InFile >>a[i]; InFile >>type[i]; } //for loop to print out injury type for(int j=1; j < = 7; j++) { //prints out type of injury based on number if (j==1) cout<< "Type 1 is a tear of the Anterior Cruciate Ligament(ACL)"<< endl; if (j==2) cout<< "Type 2 is a tear of the Medial Cartilage"<< endl; if (j==3) cout<< "Type 3 is a closed fracture of the upper Tibia"<< endl; if (j==4) cout<< "Type 4 is a sprain of the Medial Collateral Ligament(MCL)"<< endl; if (j==5) cout<< "Type 5 is a dislocation of the Patella"<< endl; if (j==6) cout<< "Type 6 is a tear of the Lateral Cartilage"<< endl; if (j==7) cout<< "Type 7 is a sprain of the Lateral Collateral Ligament(LCL)"<< endl; //tests each piece of data in database for(int i=0; i < count; i++) { //if gender is the same as user input gender, the loop will be executed if (gender == g[i]) { //separates type of injury, checks each separate category if (type[i] == j) { //if injury from database is same as the one being checked, one is added //to the count of the type of injury c_type[j]=(c_type[j]+1); //calculates BMI from of height and weight from the database bmi2 = ((w[i]*.45)/((h[i]*.0254)*(h[i]*.0254))); //if the calculated BMI is withing the user specified range, this //loop is executed if ((bmi2>=min_bmi) && (bmi2<=max_bmi)) { //one is added to the BMI count for the specific injury being tested c_bmi[j]=(c_bmi[j]+1); } //if age from database is within user specified range, this loop //is executed if ((a[i]>=min_age)&&(a[i]<=max_age)) { //one is added to the age count for the specific injury being tested c_age[j]=(c_age[j]+1); } } } } } //for loop to check the 6 types of injury and calculates results for each for(int j=1; j < = 7; j++) { //skips a line when the program is run cout<< endl; //calculates percentage for BMI of specific type of injury userperc_bmi = ((double(c_bmi[j])/double(c_type[j]))*100); //prints out results for BMI of type "j" of injury cout<< "Your percentage for type "<< j<< " using BMI is "<< userperc_bmi<< "%."<< endl; //calculates percentage for age of specific type injury userperc_age = ((double(c_age[j])/double(c_type[j]))*100); //prints out results for age of type "j" of injury cout<< "Your percentage for type "<< j<< " using age is "<< userperc_age<< "%."<< endl; userperc_bmi = 0.0; userperc_age = 0.0; } return(0); }