Question

In: Computer Science

Make this simple C++ code add data into a file called "Medical Database" preferably an excel...

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;


}

Solutions

Expert Solution

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);

}


Related Solutions

Would you make separated this code by one .h file and two .c file? **********code************* #include...
Would you make separated this code by one .h file and two .c file? **********code************* #include <stdlib.h> #include <stdbool.h> #include <stdio.h> #include<time.h> // Prints out the rules of the game of "craps". void print_game_rule(void) { printf("Rules of the game of CRAPS\n"); printf("--------------------------\n"); printf("A player rolls two dice.Each die has six faces.\n"); printf("These faces contain 1, 2, 3, 4, 5, and 6 spots.\n"); printf("After the dice have come to rest, the sum of the spots\n on the two upward faces is...
The Excel file Store and Regional Sales Database provides sales data for computers and peripherals showing...
The Excel file Store and Regional Sales Database provides sales data for computers and peripherals showing the store identification number, sales region, item number, item description, unit price, units sold, and month when the sales were made during the fourth quarter of last year.3 Modify the spreadsheet to calculate the total sales revenue for each of the eight stores as well as each of the three sales regions.
Python 3 Code does not save properly the data in the excel file. it stores the...
Python 3 Code does not save properly the data in the excel file. it stores the data in the same row over and over # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money...
USE C# to write this. 1.To the capsule, add a script called “MoveIt”. This will make...
USE C# to write this. 1.To the capsule, add a script called “MoveIt”. This will make the capsule move repeatedly between (3, 0, 0) and (-3, 0, 0), moving 1 unit per second, moving in the positive direction initially. [Note: The capsule should move toward (3,0,0) from its initial location of (0,1,0) and then move toward (-3,0,0), etc.] 2.To the yellow cube, add a script called “RotateIt”. This will make the cube rotate (30, 60, 90) per second. 3. Lastly,...
Use Excel to develop a regression model for the Hospital Database (using the “Excel Databases.xls” file...
Use Excel to develop a regression model for the Hospital Database (using the “Excel Databases.xls” file on Blackboard) to predict the number of Personnel by the number of Births. Perform a test of the overall model, what is the value of the test statistic? Write your answer as a number, round your answer to 2 decimal places. SUMMARY OUTPUT Regression Statistics Multiple R 0.697463374 R Square 0.486455158 Adjusted R Square 0.483861497 Standard Error 590.2581194 Observations 200 ANOVA df SS MS...
Develop a simple MIS (Management Information System) that consists of a simple database (a text file)....
Develop a simple MIS (Management Information System) that consists of a simple database (a text file). The system manages to dynamically input record/data into the database. The data from the database can be sorted, searched and updated. User also should be able to add new records/data, remove any data and etc. Here are some ideas of MIS that can be developed: 1. Hotel reservation system. 2. Students management system. 3. Payroll management system. 4. Bus/Railway/Plane ticketing system. 5. Clinic record...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Write the DML code to add the first row of each table to the database.
Write the DML code to add the first row of each table to the database.
Create C# code that can search a text file and output the data at the line...
Create C# code that can search a text file and output the data at the line number inputted and amount of entries needed. Example of call in command window: Search16s filename.txt 273   10 Where 273 is the line number to start the output from, and 10 is the number of sequences that the program should output. The number of sequences entered on call should always be a odd number or give an error in console. The output should also display...
C language only please and please make a simple code Write a function that will find...
C language only please and please make a simple code Write a function that will find whether there exist two integers that sum to the target integer. The function is to “return” three values.First, return “1” if the integers were found,return “-1” if your search was not successful.If you find two integers which add up to the target value, you should return their respective index position inside the array. Suggested prototype:int TwoSumFunction(int arr[], int size, int target, int*index1, int* index2);Inside...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT