Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // CS 1337.003 Project 2 <bah170030> <Bushra Hameed>
- /* A program that reads simulated patient health information from
- standard input, performs a bit of analysis on that data and outputs
- a summary of the information. */
- //============================================================================
- #include <iostream>
- using namespace std;
- // a structure of the patient's vital information
- struct PatVitals
- {
- float temperature;
- unsigned int systolicPressure;
- unsigned int diastolicPressure;
- };
- // a structure of the patient's activity information
- struct PatActivity
- {
- unsigned int stepCount;
- unsigned int sleepHours;
- };
- // create a union consisting of structures the previous structures
- union Patient
- {
- // create variables using the structure data types
- PatVitals patientVitals;
- PatActivity patientActivity;
- };
- struct Overall
- {
- int patientVitalType;
- // union previously declared
- Patient patientInfo;
- };
- // global array of the structure Overall that consists of the data type Patient
- // Patient can access structures PatVitals and PatActivity
- Overall array[100];
- int main()
- {
- int response, counter = 0, index = 0;
- // maximum temperature and pressures
- float maxTemp = 0, maxSystolic = 0, maxDiastolic = 0;
- // minimum temperature and pressures
- float minTemp = 1000, minSystolic = 1000, minDiastolic = 1000;
- // total step count and hours of sleep
- int stepTotal = 0, sleepTotal = 0;
- // prompt the user to enter the desired action
- cout << "Please enter the number of the desired action (1, 2, 3):\n";
- cout << "1 - Enter some patient vital information\n";
- cout << "2 - Enter some patient activity information\n";
- cout << "3 - Print summary information on the patient information and exit the program\n";
- // user entered response
- cin >> response;
- while (response != 3)
- {
- // this nested while loop outputs an error message
- while (response != 1 && response !=2 && response != 3)
- {
- cout << "Please enter 1, 2, or 3\n";
- cout.flush();
- cin >> response;
- }
- // if the user enters 1
- if(response == 1)
- {
- cout << "Enter the temperature: \n";
- cin >> array[counter].patientInfo.patientVitals.temperature;
- // if the variable cannot be accessed or is less than 0
- while (!array[counter].patientInfo.patientVitals.temperature ||
- array[counter].patientInfo.patientVitals.temperature < 0)
- {
- // Error message
- cout << "Please enter an integral unsigned number\n";
- cin.clear();
- cin.ignore();
- cin >> array[counter].patientInfo.patientVitals.temperature;
- }
- // check the maximum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.temperature > maxTemp)
- {
- maxTemp = array[counter].patientInfo.patientVitals.temperature;
- }
- // check the minimum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.temperature < minTemp)
- {
- minTemp = array[counter].patientInfo.patientVitals.temperature;
- }
- cout << "Enter the systolic pressure: \n";
- cin >> array[counter].patientInfo.patientVitals.systolicPressure;
- // if the variable cannot be accessed or is less than 0
- while (!array[counter].patientInfo.patientVitals.systolicPressure ||
- array[counter].patientInfo.patientVitals.systolicPressure < 0)
- {
- // Error message
- cout << "Please enter an integral unsigned number\n";
- cin.clear();
- cin.ignore();
- cin >> array[counter].patientInfo.patientVitals.systolicPressure;
- }
- // check the maximum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.systolicPressure > maxSystolic)
- {
- maxSystolic = array[counter].patientInfo.patientVitals.systolicPressure;
- }
- // check the minimum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.systolicPressure < minSystolic)
- {
- minSystolic = array[counter].patientInfo.patientVitals.systolicPressure;
- }
- cout << "Enter the diastolic pressure: \n";
- cin >> array[counter].patientInfo.patientVitals.diastolicPressure;
- // if the variable cannot be accessed or is less than 0
- while (!array[counter].patientInfo.patientVitals.diastolicPressure ||
- array[counter].patientInfo.patientVitals.diastolicPressure < 0)
- {
- // Error message
- cout << "Please enter an integral unsigned number\n";
- cin.clear();
- cin.ignore();
- cin >> array[counter].patientInfo.patientVitals.diastolicPressure;
- }
- // check the maximum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.diastolicPressure > maxDiastolic)
- {
- maxDiastolic = array[counter].patientInfo.patientVitals.diastolicPressure;
- }
- // check the minimum value and reassign if applicable
- if(array[counter].patientInfo.patientVitals.diastolicPressure < minDiastolic)
- {
- minDiastolic = array[counter].patientInfo.patientVitals.diastolicPressure;
- }
- counter++;
- }
- // if the user enters 2
- if(response == 2)
- {
- // prompt the user to enter the step count
- cout<<"Enter the step count: "<< endl;
- // input a value into the variable stepCount
- cin >> array[index].patientInfo.patientActivity.stepCount;
- // calculate the total of stepCount
- stepTotal += array[index].patientInfo.patientActivity.stepCount;
- // prompt the user to enter the number of hours of sleep
- cout<<"Enter the sleep hours: "<<endl;
- // input a value into the variable sleepHours
- cin >> array[index].patientInfo.patientActivity.sleepHours;
- // calculate the total of sleepHours
- sleepTotal += array[index].patientInfo.patientActivity.sleepHours;
- // increment the subscript
- index++;
- }
- cout << "Please enter the number of the desired action (1, 2, 3):\n";
- cout << "1 - Enter some patient vital information\n";
- cout << "2 - Enter some patient activity information\n";
- cout << "3 - Print summary information on the patient information and exit the program\n";
- cin >> response;
- } // end of while loop
- // if the user enters 3
- if(response == 3)
- {
- cout << "Number of patient vital information records: "<< index++ << endl;
- cout << "Maximum temperature: "<< maxTemp << endl;
- cout << "Minimum temperature: "<< minTemp << endl;
- cout << "Maximum Systolic Pressure: "<< maxSystolic << endl;
- cout << "Minimum Systolic Pressure: "<< minSystolic << endl;
- cout << "Maximum Diastolic Pressure: " << maxDiastolic << endl;
- cout << "Minimum Diastolic Pressure: " << minDiastolic << endl;
- cout << "Number of patient activity information records: " << counter++ << endl;
- cout << "Total step count: " << stepTotal << endl;
- cout << "Total sleep hours: " << sleepTotal << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement