In: Computer Science
Make this simple C++ code add data into a file called "Medical Database" preferably an excel file.
Also ask the patient for blood type and if they're donors.
Anytime I run this code, it should add new data into the same Medical Database file.
Use comments to explain what each line of code is doing. (including the one I have written)
Side note: I'm trying to explain how data mining works in the medical field and the medical database file is acting a the real database hospitals use for patients.
*Also if can you put a note explaining steps taken to put real data into a real Database. API calling or anything.*
#include<iostream>
#include<string>
using namespace std;
int main() {
string name;
int sytolic,diastolic;
sytolic=diastolic=0;
cout<<"Enter name of Patient: ";
getline(cin,name);
cout<<"Enter "<<name<<"'s sytolic number: ";
cin>>sytolic;
cout<<"Enter "<<name<<"'s diastolic number: ";
cin>>diastolic;
cout<<"Below is "<<name<<"'s blood pressure rating: "<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"Name of Patient: "<<name<<endl;
cout<<"Blood Pressure Ratings: "<<sytolic<<"/"<<diastolic<<endl;
if(sytolic<120 && diastolic<80)
cout<<"Blood Pressure Category: Normal"<<endl;
if(120<=sytolic && sytolic<=129 && diastolic<80)
cout<<"Blood Pressure Category: Elevated"<<endl;
if((130<=sytolic && sytolic<=139) || (80<=diastolic && diastolic<=89))
cout<<"Blood Pressure Category: HBP - Stage 1"<<endl;
if((140<=sytolic) || (90<=diastolic))
cout<<"Blood Pressure Category: HBP - Stage 2"<<endl;
}
Hope you are doing well. I will provide you 2 solution for same problem. First one as per your requirment and second for entering multiple Patent information at once.
Solution 1)
----------------------
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() {
ofstream write("Medical_Database.csv",ios::app); // write data into Medical_Database.csv file
string name;
int sytolic,diastolic;
sytolic=diastolic=0;
cout<<"Enter name of Patient: ";
getline(cin,name); // store name in name varaible which enter by user
cout<<"Enter "<<name<<"'s sytolic number: ";
cin>>sytolic; // store sytolic in sytolic varaible which enter by user
cout<<"Enter "<<name<<"'s diastolic number: ";
cin>>diastolic; // store diastolic in diastolic varaible which enter by user
cout<<"Below is "<<name<<"'s blood pressure rating: "<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"Name of Patient: "<<name<<endl; // printing name on screen
cout<<"Blood Pressure Ratings: "<<sytolic<<"/"<<diastolic<<endl; // printing sytolic/diastolic on screen
if(sytolic<120 && diastolic<80)
cout<<"Blood Pressure Category: Normal"<<endl;
if(120<=sytolic && sytolic<=129 && diastolic<80)
cout<<"Blood Pressure Category: Elevated"<<endl;
if((130<=sytolic && sytolic<=139) || (80<=diastolic && diastolic<=89))
cout<<"Blood Pressure Category: HBP - Stage 1"<<endl;
if((140<=sytolic) || (90<=diastolic))
cout<<"Blood Pressure Category: HBP - Stage 2"<<endl;
write << name; //writing name into file
write <<" "; //giving the space after name
write << sytolic; //writing sytolic into file
write <<" "; //giving the space after name
write << diastolic; //writing diastolic into file
write <<" "; //giving the space after name
write << sytolic/diastolic; //writing sytolic/diastolic into
file
write <<endl; // cursor went to new line
}
----------------------------
OUTPUT FILE DATA:
Medical_Database.csv
shashnka 120 130 0
Rohit 1500 180 8
Prashnath 125 185 0
---------------------------------
SOLUTION(2)
-------------------------------
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
// struct type class for storing the values of Patient
struct Patient{
string name; // donor varaible for storing the
donor
string donor; // donor varaible for storing the
donor
int sytolic; // name sytolic for storing the
sytolic
int diastolic; // diastolic variable for storing the
diastolic
};
// below method is used to write the data into file
void write_data(ofstream &write) {
int reapeat=1; // for repeatiton of the item
int heading=10;
while(reapeat==1){
if(heading==10){
write << "patient name"; //writing name into file
write <<" "; //giving the space after name
write << "Sytolic"; //writing sytolic into file
write <<" "; //giving the space after name
write << "Diastolic"; //writing diastolic into file
write <<" "; //giving the space after name
write << "sytolic/diastolic"; //writing sytolic/diastolic
into file
write <<" "; //giving the space after name
write << "patient is donor or not "; //writing donor into the
file
write <<endl;
heading++;
}
Patient patient; // object of Patient of class
string check="q";
cout<<"Please enter an Patient information or 'q' for
Exit:"<<endl;
cout<<"Enter name of Patient: ";
cin>>patient.name;
if(patient.name!=check){
cout<<"Enter "<<patient.name<<"'s sytolic
number: ";
cin>>patient.sytolic;
cout<<"Enter "<<patient.name<<"'s diastolic
number: ";
cin>>patient.diastolic;
cout<<"Enter "<<patient.name<<"'s Blood donor
or not: ";
cin>>patient.donor;
cout<<"Below is "<<patient.name<<"'s blood pressure rating: "<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"Name of Patient: "<<patient.name<<endl; // printing name on screen
cout<<"Blood Pressure Ratings: "<<patient.sytolic<<"/"<<patient.diastolic<<endl; // printing sytolic/diastolic on screen
if(patient.sytolic<120 && patient.diastolic<80)
cout<<"Blood Pressure Category: Normal"<<endl;
if(120<=patient.sytolic && patient.sytolic<=129 && patient.diastolic<80)
cout<<"Blood Pressure Category: Elevated"<<endl;
if((130<=patient.sytolic && patient.sytolic<=139) || (80<=patient.diastolic && patient.diastolic<=89))
cout<<"Blood Pressure Category: HBP - Stage 1"<<endl;
if((140<=patient.sytolic) || (90<=patient.diastolic))
cout<<"Blood Pressure Category: HBP - Stage 2"<<endl;
write << patient.name; //writing name into file
write <<" "; //giving the space after name
write << patient.sytolic; //writing sytolic into file
write <<" "; //giving the space after name
write << patient.diastolic; //writing diastolic into
file
write <<" "; //giving the space after name
write << patient.sytolic/patient.diastolic; //writing
sytolic/diastolic into file
write <<" "; //giving the space after name
write << patient.donor; //writing donor into the file
write <<endl; // cursor went to new line
cout<<"::::::::::::::::::::::::::::::::::::"<<endl;
}
else{
reapeat=23; // for exit the loop
}
}
}
int main(){
ofstream write("Medical_Database.csv",ios::app); // write data into
inventory.txt file
write_data(write);
}
_________________
SAMPLE OUTPUT:
Please enter an Patient information or 'q' for Exit:
Enter name of Patient: Shashank
Enter Shashank's sytolic number: 145
Enter Shashank's diastolic number: 220
Enter Shashank's Blood donor or not: YES
Below is Shashank's blood pressure rating:
----------------------------------------------
Name of Patient: Shashank
Blood Pressure Ratings: 145/220
Blood Pressure Category: HBP - Stage 2
::::::::::::::::::::::::::::::::::::
Please enter an Patient information or 'q' for Exit:
Enter name of Patient: Faisal
Enter Faisal's sytolic number: 135
Enter Faisal's diastolic number: 220
Enter Faisal's Blood donor or not: No
Below is Faisal's blood pressure rating:
----------------------------------------------
Name of Patient: Faisal
Blood Pressure Ratings: 135/220
Blood Pressure Category: HBP - Stage 1
Blood Pressure Category: HBP - Stage 2
::::::::::::::::::::::::::::::::::::
Please enter an Patient information or 'q' for Exit:
Enter name of Patient: Prashant
Enter Prashant's sytolic number: 123
Enter Prashant's diastolic number: 190
Enter Prashant's Blood donor or not: Yes
Below is Prashant's blood pressure rating:
----------------------------------------------
Name of Patient: Prashant
Blood Pressure Ratings: 123/190
Blood Pressure Category: HBP - Stage 2
::::::::::::::::::::::::::::::::::::
Please enter an Patient information or 'q' for Exit:
Enter name of Patient: q
Process returned 0 (0x0) execution time : 43.978 s
Press any key to continue.
-------------------------------
Medical_Database.csv
---------------------------------
patient name Sytolic Diastolic sytolic/diastolic patient is
donor or not
Shashank 145 220 0 YES
Faisal 135 220 0 No
Prashant 123 190 0 Yes
-------------------------
SUMMARY:
I have provided the solution as per your requirement, i hope
you're satisfied with the way i have approached. please dont
hesitate to give me a Like if you like it, i appreciate your like.
If you have any queries you can shoot them any time in comments
section. I will be glad to help you.
Thank you :)
-------------------------
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
// struct type class for storing the values of Patient
struct Patient{
string name; // donor varaible for storing the
donor
string donor; // donor varaible for storing the
donor
int sytolic; // name sytolic for storing the
sytolic
int diastolic; // diastolic variable for storing the
diastolic
};
// below method is used to write the data into file
void write_data(ofstream &write) {
int reapeat=1; // for repeatiton of the item
int heading=10;
while(reapeat==1){
if(heading==10){
write << "patient
name,Sytolic,Diastolic,sytolic/diastolic,patient is donor or not";
//writing name into file
write <<endl;
heading++;
}
Patient patient; // object of Patient of class
string check="q";
cout<<"Please enter an Patient information or 'q' for
Exit:"<<endl;
cout<<"Enter name of Patient: ";
cin>>patient.name;
if(patient.name!=check){
cout<<"Enter "<<patient.name<<"'s sytolic
number: ";
cin>>patient.sytolic;
cout<<"Enter "<<patient.name<<"'s diastolic
number: ";
cin>>patient.diastolic;
cout<<"Enter "<<patient.name<<"'s Blood donor
or not: ";
cin>>patient.donor;
cout<<"Below is "<<patient.name<<"'s blood pressure rating: "<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"Name of Patient: "<<patient.name<<endl; // printing name on screen
cout<<"Blood Pressure Ratings: "<<patient.sytolic<<"/"<<patient.diastolic<<endl; // printing sytolic/diastolic on screen
if(patient.sytolic<120 && patient.diastolic<80)
cout<<"Blood Pressure Category: Normal"<<endl;
if(120<=patient.sytolic && patient.sytolic<=129 && patient.diastolic<80)
cout<<"Blood Pressure Category: Elevated"<<endl;
if((130<=patient.sytolic && patient.sytolic<=139) || (80<=patient.diastolic && patient.diastolic<=89))
cout<<"Blood Pressure Category: HBP - Stage 1"<<endl;
if((140<=patient.sytolic) || (90<=patient.diastolic))
cout<<"Blood Pressure Category: HBP - Stage 2"<<endl;
write << patient.name;
write<<",";
write <<patient.sytolic;
write<<",";
write <<patient.diastolic;
write<<",";
write<<patient.sytolic/patient.diastolic;
write<<",";
write<<patient.donor;
write <<endl; // cursor went to new line
cout<<"::::::::::::::::::::::::::::::::::::"<<endl;
}
else{
reapeat=23; // for exit the loop
}
}
}
int main(){
ofstream write("Medical_Database.csv",ios::app); // write data into
inventory.txt file
write_data(write);
}