1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void pause()
{
system("pause");
}
int main()
{
//Declaring variables
string patient1, patient2;
string first, first2, last, last2;
string systolic, systolic2, diastolic, diastolic2;
int systolicI, systolic2I, diastolicI, diastolic2I;
string myString, myString2;
//Declaring file
ifstream patient;
//Opening file
patient.open("F://patient.DAT");
//Extracting from patient.DAT
while(! patient.eof()){
//First patient information
getline(patient, patient1);
myString = patient1;
last = myString.substr(0, 5); //Last name
first = myString.substr(6, 8); //First name
systolic = myString.substr(15, 3); //Systolic BP reading
diastolic = myString.substr(19 , 3); //Diastolic BP reading
// cout << last << ", " << first << " " << systolic << "/" << diastolic << endl; // ****Was testing to see if I extracted right
//Second patient information
getline(patient, patient2);
myString2 = patient2;
last2 = myString2.substr(0, 5); //Last name
first2 = myString2.substr(6, 3); //First name
systolic2 = myString2.substr(10, 3); //Systolic BP reading
diastolic2 = myString2.substr(14, 3); //Diastolic BP reading
// cout << last2 << ", " << first2 << " " << systolic2 << "/" << diastolic2 << endl; // ****Same as above
}
//Converting blood readings from strings to integers
systolicI = stoi(systolic);
diastolicI = stoi(diastolic);
systolic2I = stoi(systolic2);
diastolic2I = stoi(diastolic2);
//Patient 1 analysis
if (systolicI <= 119 && diastolicI <= 79){
cout << last << ", " << first << " has normal blood pressure " << systolic << "/" << diastolic << endl;
} else
if (systolicI >= 120, systolicI <= 139 && diastolicI >= 80, diastolicI <= 89){
cout << last << ", " << first << " has Hypertension " << systolic << "/" << diastolic << endl;
} else
if (systolicI >= 140, systolicI <= 159 && diastolicI >= 90, diastolicI <= 99){
cout << last << ". " << first << " has Stage 1 High Blood Pressure " << systolic << "/" << diastolic << endl;
} else {
cout << last << ". " << first << " has Stage 2 High Blood Pressure " << systolic << "/" << diastolic << endl;
}
//Patient 2 analysis
if (systolic2I <= 119 && diastolic2I <= 79){
cout << last2 << ", " << first2 << " has normal blood pressure " << systolic2 << "/" << diastolic2 << endl;
} else
if (systolic2I >= 120, systolic2I <= 139 && diastolic2I >= 80, diastolic2I <= 89){
cout << last2 << ", " << first2 << " has Hypertension " << systolic2 << "/" << diastolic2 << endl;
} else
if (systolic2I >= 140, systolic2I <= 159 && diastolic2I >= 90, diastolic2I <= 99){
cout << last2 << ". " << first2 << " has Stage 1 High Blood Pressure " << systolic2 << "/" << diastolic2 << endl;
} else {
cout << last2 << ". " << first2 << " has Stage 2 High Blood Pressure " << systolic2 << "/" << diastolic2 << endl;
}
//Closing patients file
patient.close();
//Freezing
cout << "\n";
pause();
return (0);
}
|