Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.85 KB | None | 0 0
  1. //============================================================================
  2. // CS 1337.003 Project 2 <bah170030> <Bushra Hameed>
  3.  
  4. /* A program that reads simulated patient health information from
  5. standard input, performs a bit of analysis on that data and outputs
  6. a summary of the information.   */
  7.  
  8. //============================================================================
  9.  
  10. #include <iostream>
  11. using namespace std;
  12.  
  13. // a structure of the patient's vital information
  14. struct PatVitals
  15. {
  16.     float temperature;
  17.     unsigned int systolicPressure;
  18.     unsigned int diastolicPressure;
  19. };
  20.  
  21. // a structure of the patient's activity information
  22. struct PatActivity
  23. {
  24.     unsigned int stepCount;
  25.     unsigned int sleepHours;
  26. };
  27.  
  28. // create a union consisting of structures the previous structures
  29. union Patient
  30. {
  31.     // create variables using the structure data types
  32.     PatVitals patientVitals;
  33.     PatActivity patientActivity;
  34. };
  35.  
  36. struct Overall
  37. {
  38.     int patientVitalType;
  39.  
  40.     // union previously declared
  41.     Patient patientInfo;
  42. };
  43.  
  44. // global array of the structure Overall that consists of the data type Patient
  45. // Patient can access structures PatVitals and PatActivity
  46. Overall array[100];
  47.  
  48. int main()
  49. {
  50.  
  51.     int response, counter = 0, index = 0;
  52.  
  53.     // maximum temperature and pressures
  54.     float maxTemp = 0, maxSystolic = 0, maxDiastolic = 0;
  55.  
  56.     // minimum temperature and pressures
  57.     float minTemp = 1000, minSystolic = 1000, minDiastolic = 1000;
  58.  
  59.     // total step count and hours of sleep
  60.     int stepTotal = 0, sleepTotal = 0;
  61.  
  62.     // prompt the user to enter the desired action
  63.  
  64.             cout << "Please enter the number of the desired action (1, 2, 3):\n";
  65.             cout << "1 - Enter some patient vital information\n";
  66.             cout << "2 - Enter some patient activity information\n";
  67.             cout << "3 - Print summary information on the patient information and exit the program\n";
  68.  
  69.             // user entered response
  70.             cin >> response;
  71.  
  72.     while (response != 3)
  73.     {
  74.         // this nested while loop outputs an error message
  75.                 while (response != 1 && response !=2 && response != 3)
  76.                 {
  77.                     cout << "Please enter 1, 2, or 3\n";
  78.                     cout.flush();
  79.                     cin >> response;
  80.  
  81.                 }
  82.         // if the user enters 1
  83.         if(response == 1)
  84.         {
  85.  
  86.             cout << "Enter the temperature: \n";
  87.             cin >> array[counter].patientInfo.patientVitals.temperature;
  88.  
  89.             // if the variable cannot be accessed or is less than 0
  90.             while (!array[counter].patientInfo.patientVitals.temperature ||
  91.                     array[counter].patientInfo.patientVitals.temperature < 0)
  92.             {
  93.                 // Error message
  94.                 cout << "Please enter an integral unsigned number\n";
  95.                 cin.clear();
  96.                 cin.ignore();
  97.                 cin >> array[counter].patientInfo.patientVitals.temperature;
  98.             }
  99.  
  100.             // check the maximum value and reassign if applicable
  101.             if(array[counter].patientInfo.patientVitals.temperature > maxTemp)
  102.             {
  103.                 maxTemp = array[counter].patientInfo.patientVitals.temperature;
  104.             }
  105.  
  106.             // check the minimum value and reassign if applicable
  107.             if(array[counter].patientInfo.patientVitals.temperature < minTemp)
  108.             {
  109.                 minTemp = array[counter].patientInfo.patientVitals.temperature;
  110.             }
  111.  
  112.             cout << "Enter the systolic pressure: \n";
  113.             cin >> array[counter].patientInfo.patientVitals.systolicPressure;
  114.  
  115.             // if the variable cannot be accessed or is less than 0
  116.             while (!array[counter].patientInfo.patientVitals.systolicPressure ||
  117.                     array[counter].patientInfo.patientVitals.systolicPressure < 0)
  118.             {
  119.                 // Error message
  120.                 cout << "Please enter an integral unsigned number\n";
  121.                 cin.clear();
  122.                 cin.ignore();
  123.                 cin >> array[counter].patientInfo.patientVitals.systolicPressure;
  124.             }
  125.  
  126.             // check the maximum value and reassign if applicable
  127.             if(array[counter].patientInfo.patientVitals.systolicPressure > maxSystolic)
  128.             {
  129.                 maxSystolic = array[counter].patientInfo.patientVitals.systolicPressure;
  130.             }
  131.  
  132.             // check the minimum value and reassign if applicable
  133.             if(array[counter].patientInfo.patientVitals.systolicPressure < minSystolic)
  134.             {
  135.                 minSystolic = array[counter].patientInfo.patientVitals.systolicPressure;
  136.             }
  137.  
  138.  
  139.             cout << "Enter the diastolic pressure: \n";
  140.             cin >> array[counter].patientInfo.patientVitals.diastolicPressure;
  141.  
  142.             // if the variable cannot be accessed or is less than 0
  143.             while (!array[counter].patientInfo.patientVitals.diastolicPressure ||
  144.                     array[counter].patientInfo.patientVitals.diastolicPressure < 0)
  145.             {
  146.                 // Error message
  147.                 cout << "Please enter an integral unsigned number\n";
  148.                 cin.clear();
  149.                 cin.ignore();
  150.                 cin >> array[counter].patientInfo.patientVitals.diastolicPressure;
  151.             }
  152.  
  153.             // check the maximum value and reassign if applicable
  154.             if(array[counter].patientInfo.patientVitals.diastolicPressure > maxDiastolic)
  155.             {
  156.                 maxDiastolic = array[counter].patientInfo.patientVitals.diastolicPressure;
  157.             }
  158.  
  159.             // check the minimum value and reassign if applicable
  160.             if(array[counter].patientInfo.patientVitals.diastolicPressure < minDiastolic)
  161.             {
  162.                 minDiastolic = array[counter].patientInfo.patientVitals.diastolicPressure;
  163.             }
  164.  
  165.  
  166.             counter++;
  167.  
  168.         }
  169.  
  170.         // if the user enters 2
  171.         if(response == 2)
  172.         {
  173.             // prompt the user to enter the step count
  174.             cout<<"Enter the step count: "<< endl;
  175.  
  176.             // input a value into the variable stepCount
  177.             cin >> array[index].patientInfo.patientActivity.stepCount;
  178.  
  179.             // calculate the total of stepCount
  180.             stepTotal += array[index].patientInfo.patientActivity.stepCount;
  181.  
  182.             // prompt the user to enter the number of hours of sleep
  183.             cout<<"Enter the sleep hours: "<<endl;
  184.  
  185.             // input a value into the variable sleepHours
  186.             cin >> array[index].patientInfo.patientActivity.sleepHours;
  187.  
  188.             // calculate the total of sleepHours
  189.             sleepTotal += array[index].patientInfo.patientActivity.sleepHours;
  190.  
  191.             // increment the subscript
  192.             index++;
  193.  
  194.         }
  195.  
  196.  
  197.         cout << "Please enter the number of the desired action (1, 2, 3):\n";
  198.                     cout << "1 - Enter some patient vital information\n";
  199.                     cout << "2 - Enter some patient activity information\n";
  200.                     cout << "3 - Print summary information on the patient information and exit the program\n";
  201.  
  202.  
  203.         cin >> response;
  204.     } // end of while loop
  205.  
  206.         // if the user enters 3
  207.         if(response == 3)
  208.         {
  209.  
  210.             cout << "Number of patient vital information records: "<< index++ << endl;
  211.             cout << "Maximum temperature: "<< maxTemp << endl;
  212.             cout << "Minimum temperature: "<< minTemp << endl;
  213.             cout << "Maximum Systolic Pressure: "<< maxSystolic << endl;
  214.             cout << "Minimum Systolic Pressure: "<< minSystolic << endl;
  215.             cout << "Maximum Diastolic Pressure: " << maxDiastolic << endl;
  216.             cout << "Minimum Diastolic Pressure: " << minDiastolic << endl;
  217.             cout << "Number of patient activity information records: " << counter++ << endl;
  218.             cout << "Total step count: " << stepTotal << endl;
  219.             cout << "Total sleep hours: " << sleepTotal << endl;
  220.  
  221.         }
  222.  
  223.  
  224.  
  225.  
  226.     return 0;
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement