fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 6 P. 373 #14
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Patient's Hospital Charges
  6.  * ____________________________________________________________________________
  7.  * This program determines a patient's charges for their hospital stay
  8.  * depending on whether they are an in-patient or an out-patient.
  9.  *
  10.  * Formulas used:
  11.  * In-Patient:
  12.  * totalCharges = (days * dailyRate) + medication + services
  13.  * Out-Patient:
  14.  * totalCharges = medication + services
  15.  * ____________________________________________________________________________
  16.  * Input
  17.  * patientType //Whether the patient was in or out of the hospital
  18.  * days //Amount of days the patient spent in the hospital
  19.  * dailyRate //Rate of stay for patient in the hospital
  20.  * medication //Price of medication given/taken by patient
  21.  * services //Price of services (labs, etc.)
  22.  * Output
  23.  * totalCharges //Total amount charged for the patients hospital experience
  24.  *****************************************************************************/
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28. //Function Prototypes
  29. float calculate_in_charges(int days, float dailyRate, float medication, float services);
  30. float calculate_out_charges(float medication, float services);
  31.  
  32. int main() {
  33. //Data Dictionary
  34. char patientType; //INPUT - Whether the patient was an in or out patient
  35. int days; //INPUT - Amount of days the patient spent in the hospital
  36. float dailyRate; //INPUT - Rate of stay for patient in the hospital
  37. float medication; //INPUT - Price of medication given/taken by patient
  38. float services; //INPUT - Price of services (labs, etc.)
  39. float totalCharges; //OUTPUT - Total amount charged for the patients hospital experience
  40.  
  41. cout << fixed << setprecision(2);
  42. cout << "Was the patient an In-Patient or an Out-patient? (I/O): " << endl;
  43. cin >> patientType;
  44. //Validate Input
  45. while (patientType != 'I' && patientType != 'O'){
  46. cout << "Invalid input. Please enter 'I' for In-Patient or 'O' for Out-Patient: ";
  47. cin >> patientType;
  48. }
  49. //In-Patient Path
  50. if (patientType == 'I'){
  51. cout << "In-Patient Information: " << endl;
  52. cout << "Enter number of days spent in the hospital: " << endl;
  53. cin >> days;
  54. if (days < 0){
  55. cout << "Please enter a non negative number: " << endl;
  56. cin >> days;
  57. }
  58. cout << "Enter daily rate: $" << endl;
  59. cin >> dailyRate;
  60. if (dailyRate < 0){
  61. cout << "Invalid input, please enter a non negative number: " << endl;
  62. cin >> dailyRate;
  63. }
  64. cout << "Enter hospital medication charges: $" << endl;
  65. cin >> medication;
  66. if (medication < 0){
  67. cout << "Invalid input, please enter a non negative number: " << endl;
  68. cin >> medication;
  69. }
  70. cout << "Enter charges for hospital services (lab tests, etc.): $" << endl;
  71. cin >> services;
  72. if (services < 0){
  73. cout << "Invalid input, please enter a non negative number: " << endl;
  74. cin >> services;
  75. }
  76. totalCharges = calculate_in_charges(days, dailyRate, medication, services);
  77. }
  78. //Out-Patient Path
  79. else {
  80. cout << "Out-Patient Information: " << endl;
  81. cout << "Enter hospital medication charges: $" << endl;
  82. cin >> medication;
  83. if (medication < 0){
  84. cout << "Invalid input, please enter a non negtaive number: $" << endl;
  85. cin >> medication;}
  86. else{
  87. cout << "Enter charges for hospital services (lab tests, etc.): $" << endl;
  88. cin >> services;}
  89. if (services < 0){
  90. cout << "Invalid input, please enter a non negative number: $" << endl;
  91. cin >> services;}
  92. totalCharges = calculate_out_charges (medication, services);
  93. }
  94. //Display Total
  95. cout << "Total Hospital Charges: $" << totalCharges << endl;
  96. return 0;
  97. }
  98. //In-Patient Function
  99. float calculate_in_charges(int days, float dailyRate, float medication, float services)
  100. {
  101. return (days * dailyRate) + medication + services;
  102. }
  103. //Out-Patient Function
  104. float calculate_out_charges(float medication, float services)
  105. {
  106. return medication + services;
  107. }
Success #stdin #stdout 0s 5312KB
stdin
O
400
2000
stdout
Was the patient an In-Patient or an Out-patient? (I/O): 
Out-Patient Information: 
Enter hospital medication charges: $
Enter charges for hospital services (lab tests, etc.): $
Total Hospital Charges: $2400.00