In: Computer Science
"Health Data has the power to inform, excite, and influence behavior that leads to improved health at the individual and population level." - The Beauty of Health Data Design an application that provides health information to the user. The application should include: 1) loops 2) files 3) methods (pass by value/pass by reference, overloading methods) 4) global / local variables / static variables coding language c++ an example of health data would be checking someone blood oxygen, temp, etc.the output needs to tell if the person is healthy or not
code in c++ which includes
code to copy
#include<bits/stdc++.h>
using namespace std;
int healthyMinBloodOxygenLevel=97;//example of global variables
int healthyMaxBloodSugarLevel=100;//example of global variables
int healthyMinBodyTemperature=36;//example of global variables
int healthyMaxBodyTemperature=38;//example of global variables
class PatientData{
private:
string patientName;
int bloodOxygenLevel;
int bodyTemperatureInDegreeCelcius;
int bloodSugarLevel;
public:
//example of overloaded methods (in this case these are overloaded constructors)
PatientData(string name){
patientName=name;
}
PatientData(string name,int bloodoxygen, int temp, int bloodSugar){
patientName=name;
bloodOxygenLevel=bloodoxygen;
bodyTemperatureInDegreeCelcius=temp;
bloodSugarLevel=bloodSugar;
}
void healthy(bool &isHealthy){//example of pass by reference
if(bloodOxygenLevel>=healthyMinBloodOxygenLevel && bloodSugarLevel<=healthyMaxBloodSugarLevel && bodyTemperatureInDegreeCelcius>=healthyMinBodyTemperature &&
bodyTemperatureInDegreeCelcius<=healthyMaxBodyTemperature){
isHealthy = true;
}else{
isHealthy = false;
}
}
//this includes file writing operations
bool saveData(string filename){//returns if savinf was complete
ofstream outfile(filename);
if(!outfile){
return false;
}
outfile<<patientName<<" "<<bloodOxygenLevel<<" "<<bodyTemperatureInDegreeCelcius<<" "<<bloodSugarLevel<<endl;
outfile.close();
return true;
}
//this includes file reading operations
bool loadData(string filename){
ifstream infile(filename);
if(!infile){
return false;
}
string buffer;
while(infile>>buffer){
if(buffer==patientName){
infile>>bloodOxygenLevel;
infile>>bodyTemperatureInDegreeCelcius;
infile>>bloodSugarLevel;
infile.close();
return true;
}
}
return false;
}
};
int main()
{
string filename = "patientData.txt";
while(true){
int choice;
cout<<"Enter 1 to add patient data\nEnter 2 to get patient data\nEnter 3 to exit"<<endl;
cin>>choice;
switch(choice){
case 1: {
//declare variables to take input;
string patientName;
int bloodOxygenLevel;
int bodyTemperatureInDegreeCelcius;
int bloodSugarLevel;
cout<<"Enter Patient Name: ";
cin>>patientName;
cout<<"Enter Patient blood oxygen level: ";
cin>>bloodOxygenLevel;
cout<<"Enter Patient body temperatire ";
cin>>bodyTemperatureInDegreeCelcius;
cout<<"Enter Patient blood sugar level: ";
cin>>bloodSugarLevel;
PatientData p(patientName, bloodOxygenLevel, bodyTemperatureInDegreeCelcius, bloodSugarLevel);
p.saveData(filename);
bool isHealthy;
p.healthy(isHealthy);
if(isHealthy){
cout<<patientName<<" is Healthy"<<endl;
}else{
cout<<patientName<<" is Healthy"<<endl;
}
break;
}
case 2:{
string patientName;
cout<<"Enter Patient Name: ";
cin>>patientName;
PatientData p(patientName);
if(p.loadData(filename)){
bool isHealthy;
p.healthy(isHealthy);
if(isHealthy){
cout<<patientName<<" is Healthy"<<endl;
}else{
cout<<patientName<<" is Healthy"<<endl;
}
}else{
cout<<"Patient "<<patientName<<" not found in database."<<endl;
}
break;
}
case 3: exit(0);
}
}
}
code screenshot
output screenshot