/** * * Project 1 - the Framingham Risk Calculator * http://en.wikipedia.org/wiki/Framingham_Risk_Score#The_Framingham_Risk_Score_in_detail * * @author Clay Shields * **/ #include using namespace std; int main( ) { // There are many, many constants in the computation // We will set them up // Define the ranges for age, total cholesterol, hdl cholesterol // and systolic pressure const int kAgeRange1Min = 20; const int kAgeRange1Max = 34; const int kAgeRange2Min = 35; const int kAgeRange2Max = 39; const int kAgeRange3Min = 40; const int kAgeRange3Max = 44; const int kAgeRange4Min = 45; const int kAgeRange4Max = 49; const int kAgeRange5Min = 50; const int kAgeRange5Max = 54; const int kAgeRange6Min = 55; const int kAgeRange6Max = 59; const int kAgeRange7Min = 60; const int kAgeRange7Max = 64; const int kAgeRange8Min = 65; const int kAgeRange8Max = 69; const int kAgeRange9Min = 70; const int kAgeRange9Max = 74; const int kAgeRange10Min = 75; const int kAgeRange10Max = 79; const int kTotalCholesterolRange1Min = 130; const int kTotalCholesterolRange1Max = 159; const int kTotalCholesterolRange2Min = 160; const int kTotalCholesterolRange2Max = 199; const int kTotalCholesterolRange3Min = 200; const int kTotalCholesterolRange3Max = 239; const int kTotalCholesterolRange4Min = 200; const int kTotalCholesterolRange4Max = 239; const int kTotalCholesterolRange5Min = 240; const int kTotalCholesterolRange5Max = 320; const int kHDLCholesterolRange1Min = 20; const int kHDLCholesterolRange1Max = 39; const int kHDLCholesterolRange2Min = 40; const int kHDLCholesterolRange2Max = 49; const int kHDLCholesterolRange3Min = 50; const int kHDLCholesterolRange3Max = 59; const int kHDLCholesterolRange4Min = 60; // People who are over 125 probably no longer measure risk const int kHDLCholesterolRange4Max = 100; const int kSystolicRange1Min = 90; const int kSystolicRange1Max = 119; const int kSystolicRange2Min = 120; const int kSystolicRange2Max = 129; const int kSystolicRange3Min = 130; const int kSystolicRange3Max = 139; const int kSystolicRange4Min = 140; const int kSystolicRange4Max = 159; const int kSystolicRange5Min = 160; const int kSystolicRange5Max = 300; // Set constants for the points for various ranges const int kAge1Score = -7; const int kAge2Score = -3; const int kAge3Score = 0; const int kAge4Score = 3; const int kAge5Score = 6; const int kAge6Score = 8; const int kAge7Score = 10; const int kAge8Score = 12; const int kAge9Score = 14; const int kAge10Score = 16; // //Age 20–39 years: // Under 160: 0 points. // 160-199: 4 points. // 200-239: 8 points. // 240-279: 11 points. // 280 or higher: 13 points. const int kAge12TotChol1 = 0; const int kAge12TotChol2 = 4; const int kAge12TotChol3 = 8; const int kAge12TotChol4 = 11; const int kAge12TotChol5 = 13; // Age 40–49 years: // Under 160: 0 points. // 160-199: 3 points. // 200-239: 6 points. // 240-279: 8 points. // 280 or higher: 10 points. • const int kAge34TotChol1 = 0; const int kAge34TotChol2 = 3; const int kAge34TotChol3 = 6; const int kAge34TotChol4 = 8; const int kAge34TotChol5 = 10; // Age 50–59 years: // Under 160: 0 points. // 160-199: 2 points. // 200-239: 4 points. // 240-279: 5 points. // 280 or higher: 7 points. • const int kAge56TotChol1 = 0; const int kAge56TotChol2 = 2; const int kAge56TotChol3 = 4; const int kAge56TotChol4 = 5; const int kAge56TotChol5 = 7; // Age 60–69 years: // Under 160: 0 points. // 160-199: 1 point. // 200-239: 2 points. // 240-279: 3 points. // 280 or higher: 4 points. • const int kAge78TotChol1 = 0; const int kAge78TotChol2 = 1; const int kAge78TotChol3 = 2; const int kAge78TotChol4 = 3; const int kAge78TotChol5 = 4; // Age 70–79 years: // Under 160: 0 points. // 160-199: 1 point. // 200-239: 1 point. // 240-279: 2 points. // 280 or higher: 2 points. const int kAge910TotChol1 = 0; const int kAge910TotChol2 = 1; const int kAge910TotChol3 = 1; const int kAge910TotChol4 = 2; const int kAge910TotChol5 = 2; // Whew, through the big one // Now smoking points const int kSmokerAge12 = 9; const int kSmokerAge34 = 7; const int kSmokerAge56 = 4; const int kSmokerAge78 = 2; const int kSmokerAge910 = 1; // Now HDL cholesterol points const int kHDL1 = 2; const int kHDL2 = 1; const int kHDL3 = 0; const int kHDL4 = -1; // Finally, the systolic blood pressure points const int kSystolic1 = 0; const int kSystolic2 = 1; const int kSystolic3 = 2; const int kSystolic4 = 3; const int kSystolic5 = 4; // Now the conversion ranges for the total score const int kTotalRange1Min = -10; const int kTotalRange1Max = 8; const int kTotalRange2Min = 9; const int kTotalRange2Max = 12; const int kTotalRange3Min = 13; const int kTotalRange3Max = 14; const int kTotalRange4Min = 15; const int kTotalRange4Max = 15; const int kTotalRange5Min = 16; const int kTotalRange5Max = 16; const int kTotalRange6Min = 17; const int kTotalRange6Max = 17; const int kTotalRange7Min = 18; const int kTotalRange7Max = 18; const int kTotalRange8Min = 19; const int kTotalRange8Max = 19; const int kTotalRange9Min = 20; const int kTotalRange9Max = 20; const int kTotalRange10Min = 21; const int kTotalRange10Max = 21; const int kTotalRange11Min = 22; const int kTotalRange11Max = 22; const int kTotalRange12Min = 23; const int kTotalRange12Max = 23; const int kTotalRange13Min = 24; const int kTotalRange13Max = 24; const int kTotalRange14Min = 25; const int kTotalRange14Max = 30; const string kTotal1Score = "<1%"; const string kTotal2Score = "1%"; const string kTotal3Score = "2%"; const string kTotal4Score = "3%"; const string kTotal5Score = "4%"; const string kTotal6Score = "5%"; const string kTotal7Score = "6%"; const string kTotal8Score = "8%"; const string kTotal9Score = "11%"; const string kTotal10Score = "14%"; const string kTotal11Score = "17%"; const string kTotal12Score = "22%"; const string kTotal13Score = "27%"; const string kTotal14Score = "over 30%"; // Variable declarations int age; int total_cholesterol; int hdl_cholesterol; char smoker_input; bool smoker; int systolic_blood_pressure; int total_score = 0; int age_range; int total_cholesterol_range; int hdl_cholesterol_range; int systolic_blood_pressure_range; // Here is my overall algorithm // Get the input for what we need: // - Age // - Total cholesterol // - HDL cholesterol // - Smoker // - Systolic blood pressure // Then determine which ranges these fall into // This will make the logic for points easier as we can use switch statements cout << "Framingham Risk Score Calculator - Female only" << endl; cout << "Please have the following subject information at hand: " << endl; cout << " - Age" << endl; cout << " - Smoker status" << endl; cout << " - Total Cholesterol" << endl; cout << " - HDL Cholesterol" << endl; cout << " - Age" << endl; cout << " - Systolic Blood Pressure" << endl; cout << endl << endl; // Read in the age and do some error checking cout << "Please enter the patients age: "; cin >> age; if ((age < kAgeRange1Min) || (age > kAgeRange10Max)){ cout << "We have no data for determining risk of people who are " << age << " years old" << endl; return 0; } // Set the age range if ((age >= kAgeRange1Min) && (age <= kAgeRange1Max)) { age_range = 1; } else if ((age >= kAgeRange2Min) && (age <= kAgeRange2Max)) { age_range = 2; } else if ((age >= kAgeRange3Min) && (age <= kAgeRange3Max)) { age_range = 3; } else if ((age >= kAgeRange4Min) && (age <= kAgeRange4Max)) { age_range = 4; } else if ((age >= kAgeRange5Min) && (age <= kAgeRange5Max)) { age_range = 5; } else if ((age >= kAgeRange6Min) && (age <= kAgeRange6Max)) { age_range = 6; } else if ((age >= kAgeRange7Min) && (age <= kAgeRange7Max)) { age_range = 7; } else if ((age >= kAgeRange8Min) && (age <= kAgeRange8Max)) { age_range = 8; } else if ((age >= kAgeRange9Min) && (age <= kAgeRange9Max)) { age_range = 9; } else if ((age >= kAgeRange10Min) && (age <= kAgeRange10Max)) { age_range = 10; } //cerr << "Age range was: " << age_range << endl; cout << "Is the patient a smoker (Y/N)?: "; cin >> smoker_input; switch (smoker_input) { case 'Y': case 'y': smoker = true; break; case 'N': case 'n': smoker = false; break; default: cout << "Choice must be Y or N for yes or no" << endl; return 0; } //cerr << "Smoker was: " << smoker << endl; cout << "Please enter the patients total cholesterol: "; cin >> total_cholesterol; if ((total_cholesterol < kTotalCholesterolRange1Min)|| (total_cholesterol > kTotalCholesterolRange5Max)) { cout << "A total cholesterol of " << total_cholesterol << " just seems too weird" << endl; return 0; } // set the total cholesterol range if ((total_cholesterol >= kTotalCholesterolRange1Min) && (total_cholesterol <= kTotalCholesterolRange1Max)) { total_cholesterol_range = 1; } else if ((total_cholesterol >= kTotalCholesterolRange2Min) && (total_cholesterol <= kTotalCholesterolRange2Max)) { total_cholesterol_range = 2; } else if ((total_cholesterol >= kTotalCholesterolRange3Min) && (total_cholesterol <= kTotalCholesterolRange3Max)) { total_cholesterol_range = 3; } else if ((total_cholesterol >= kTotalCholesterolRange4Min) && (total_cholesterol <= kTotalCholesterolRange4Max)) { total_cholesterol_range = 4; } else if ((total_cholesterol >= kTotalCholesterolRange5Min) && (total_cholesterol <= kTotalCholesterolRange5Max)) { total_cholesterol_range = 5; } //cerr << "Total CHOL range was: " << total_cholesterol_range << endl; // enter the HDL cholesterol cout << "Please enter the patients HDL cholesterol: "; cin >> hdl_cholesterol; if ((hdl_cholesterol < kHDLCholesterolRange1Min)|| (hdl_cholesterol > kHDLCholesterolRange4Max)) { cout << "A HDL cholesterol of " << hdl_cholesterol << " just seems too weird" << endl; return 0; } if (total_cholesterol < hdl_cholesterol){ cout << "HDL Cholesterol cannot be higher than the total cholesterol" << endl; return 0; } // set the HDL cholesterol range if ((hdl_cholesterol >= kHDLCholesterolRange1Min) && (hdl_cholesterol <= kHDLCholesterolRange1Max)) { hdl_cholesterol_range = 1; } else if ((hdl_cholesterol >= kHDLCholesterolRange2Min) && (hdl_cholesterol <= kHDLCholesterolRange2Max)) { hdl_cholesterol_range = 2; } else if ((hdl_cholesterol >= kHDLCholesterolRange3Min) && (hdl_cholesterol <= kHDLCholesterolRange3Max)) { hdl_cholesterol_range = 3; } else if ((hdl_cholesterol >= kHDLCholesterolRange4Min) && (hdl_cholesterol <= kHDLCholesterolRange4Max)) { hdl_cholesterol_range = 4; } //cerr << "HDL CHOL range was: " << hdl_cholesterol_range << endl; // Enter the systolic blood pressure cout << "Please enter the patients systolic blood pressure: "; cin >> systolic_blood_pressure; if ((systolic_blood_pressure < kSystolicRange1Min)|| (systolic_blood_pressure > kSystolicRange5Max)) { cout << "A systolic blood pressure of " << systolic_blood_pressure << " just seems too weird" << endl; return 0; } // Set the systolic blood pressure range if ((systolic_blood_pressure >= kSystolicRange1Min) && (systolic_blood_pressure < kSystolicRange1Max)) { systolic_blood_pressure_range = 1; } else if ((systolic_blood_pressure >= kSystolicRange2Min) && (systolic_blood_pressure <= kSystolicRange2Max)) { systolic_blood_pressure_range = 2; } else if ((systolic_blood_pressure >= kSystolicRange3Min) && (systolic_blood_pressure <= kSystolicRange3Max)) { systolic_blood_pressure_range = 3; } else if ((systolic_blood_pressure >= kSystolicRange4Min) && (systolic_blood_pressure <= kSystolicRange4Max)) { systolic_blood_pressure_range = 4; } else if ((systolic_blood_pressure >= kSystolicRange5Min) && (systolic_blood_pressure <= kSystolicRange5Max)) { systolic_blood_pressure_range = 5; } //cerr << "Systolic range was: " << systolic_blood_pressure_range << endl; ///////////////////// // Ok, all the values and ranges are sorted out, so do some addition // First, points for age and then cholesterol level switch (age_range){ case 1: total_score += kAge1Score; switch (total_cholesterol_range) { case 1: total_score += kAge12TotChol1; break; case 2: total_score += kAge12TotChol2; break; case 3: total_score += kAge12TotChol3; break; case 4: total_score += kAge12TotChol4; break; case 5: total_score += kAge12TotChol5; break; } break; case 2: total_score += kAge2Score; switch (total_cholesterol_range) { case 1: total_score += kAge12TotChol1; break; case 2: total_score += kAge12TotChol2; break; case 3: total_score += kAge12TotChol3; break; case 4: total_score += kAge12TotChol4; break; case 5: total_score += kAge12TotChol5; break; } break; case 3: total_score += kAge3Score; switch (total_cholesterol_range) { case 1: total_score += kAge34TotChol1; break; case 2: total_score += kAge34TotChol2; break; case 3: total_score += kAge34TotChol3; break; case 4: total_score += kAge34TotChol4; break; case 5: total_score += kAge34TotChol5; break; } break; case 4: total_score += kAge4Score; switch (total_cholesterol_range) { case 1: total_score += kAge34TotChol1; break; case 2: total_score += kAge34TotChol2; break; case 3: total_score += kAge34TotChol3; break; case 4: total_score += kAge34TotChol4; break; case 5: total_score += kAge34TotChol5; break; } break; case 5: total_score += kAge5Score; switch (total_cholesterol_range) { case 1: total_score += kAge56TotChol1; break; case 2: total_score += kAge56TotChol2; break; case 3: total_score += kAge56TotChol3; break; case 4: total_score += kAge56TotChol4; break; case 5: total_score += kAge56TotChol5; break; } break; case 6: total_score += kAge6Score; switch (total_cholesterol_range) { case 1: total_score += kAge56TotChol1; break; case 2: total_score += kAge56TotChol2; break; case 3: total_score += kAge56TotChol3; break; case 4: total_score += kAge56TotChol4; break; case 5: total_score += kAge56TotChol5; break; } break; case 7: total_score += kAge7Score; switch (total_cholesterol_range) { case 1: total_score += kAge78TotChol1; break; case 2: total_score += kAge78TotChol2; break; case 3: total_score += kAge78TotChol3; break; case 4: total_score += kAge78TotChol4; break; case 5: total_score += kAge78TotChol5; break; } break; case 8: total_score += kAge8Score; switch (total_cholesterol_range) { case 1: total_score += kAge78TotChol1; break; case 2: total_score += kAge78TotChol2; break; case 3: total_score += kAge78TotChol3; break; case 4: total_score += kAge78TotChol4; break; case 5: total_score += kAge78TotChol5; break; } break; case 9: total_score += kAge9Score; switch (total_cholesterol_range) { case 1: total_score += kAge910TotChol1; break; case 2: total_score += kAge910TotChol2; break; case 3: total_score += kAge910TotChol3; break; case 4: total_score += kAge910TotChol4; break; case 5: total_score += kAge910TotChol5; break; } break; case 10: total_score += kAge10Score; switch (total_cholesterol_range) { case 1: total_score += kAge910TotChol1; break; case 2: total_score += kAge910TotChol2; break; case 3: total_score += kAge910TotChol3; break; case 4: total_score += kAge910TotChol4; break; case 5: total_score += kAge910TotChol5; break; } break; } //cerr << "Total score after age-related: " << total_score << endl; // add points for smoking if (smoker){ switch (age_range) { case 1: case 2: total_score += kSmokerAge12; break; case 3: case 4: total_score += kSmokerAge34; break; case 5: case 6: total_score += kSmokerAge56; break; case 7: case 8: total_score += kSmokerAge78; break; case 9: case 10: total_score += kSmokerAge910; break; } } //cerr << "Total score after smoking: " << total_score << endl; // add points for Systolic blood pressure switch (systolic_blood_pressure_range) { case 1: total_score += kSystolic1; break; case 2: total_score += kSystolic2; break; case 3: total_score += kSystolic3; break; case 4: total_score += kSystolic4; break; case 5: total_score += kSystolic5; break; } //cerr << "Total score after bp: " << total_score << endl; // add points for HDL Cholesterol switch (hdl_cholesterol_range) { case 1: total_score += kHDL1; break; case 2: total_score += kHDL2; break; case 3: total_score += kHDL3; break; case 4: total_score += kHDL4; break; } cout << "Total points: " << total_score << endl; string results; // Set the age range if ((total_score >= kTotalRange1Min) && (total_score <= kTotalRange1Max)) { results = kTotal1Score; } else if ((total_score >= kTotalRange2Min) && (total_score <= kTotalRange2Max)) { results = kTotal2Score; } else if ((total_score >= kTotalRange3Min) && (total_score <= kTotalRange3Max)) { results = kTotal3Score; } else if ((total_score >= kTotalRange4Min) && (total_score <= kTotalRange4Max)) { results = kTotal4Score; } else if ((total_score >= kTotalRange5Min) && (total_score <= kTotalRange5Max)) { results = kTotal5Score; } else if ((total_score >= kTotalRange6Min) && (total_score <= kTotalRange6Max)) { results = kTotal6Score; } else if ((total_score >= kTotalRange7Min) && (total_score <= kTotalRange7Max)) { results = kTotal7Score; } else if ((total_score >= kTotalRange8Min) && (total_score <= kTotalRange8Max)) { results = kTotal8Score; } else if ((total_score >= kTotalRange9Min) && (total_score <= kTotalRange9Max)) { results = kTotal9Score; } else if ((total_score >= kTotalRange10Min) && (total_score <= kTotalRange10Max)) { results = kTotal10Score; } else if ((total_score >= kTotalRange11Min) && (total_score <= kTotalRange11Max)) { results = kTotal11Score; } else if ((total_score >= kTotalRange12Min) && (total_score <= kTotalRange12Max)) { results = kTotal12Score; } else if ((total_score >= kTotalRange13Min) && (total_score <= kTotalRange13Max)) { results = kTotal13Score; } else if ((total_score >= kTotalRange14Min) && (total_score <= kTotalRange14Max)) { results = kTotal14Score; } cout << "This patient has a " << results << " chance of developing cardiovascular disease " << "in the next ten years." << endl; return 0; }