fork download
  1. //Andres Guzman CSC5 Chapter 6, P. 373, #14
  2. //
  3. /*******************************************************************************
  4. *
  5. * CALCULATE HOSPITAL BILL
  6. * ______________________________________________________________________________
  7. * This program will calculate the total bill of a hospital as either a in or out
  8. * patient
  9. *
  10. * Computation:
  11. *
  12. * total = (day * rate) + charges + services, total = charges + services
  13. * ______________________________________________________________________________
  14. * INPUT
  15. *
  16. * answer = allows user to input either in or out
  17. * days = Number of days spent in hospital
  18. * rate = charge of stay per day
  19. * charges = cost of medications
  20. * services = cost of hospital services
  21. *
  22. * OUTPUT
  23. * total = All charges added up for in and out patient
  24. *******************************************************************************/
  25. #include <iostream>
  26. #include <iomanip>
  27. #include <string>
  28. using namespace std;
  29.  
  30. double patient(string In); //overloaded function prototype
  31. double patient(string Out); //overloaded funcntion prototype
  32.  
  33. int main()
  34. {
  35. string answer; //Holds string input for user to enter in or out
  36. cout << "Was the Patient admitted as an In-Patient or Out-Patient? ";
  37. cin >> answer;
  38. cout << endl;
  39. //Creating while loop for input validation
  40. while (answer != "In" && answer != "Out" && answer != "out"
  41. && answer != "in" && answer != "IN" && answer != "OUT") //Allows only
  42. //either in or
  43. //out input.
  44. {
  45. cout << "Invalid Patient Type." << endl;
  46. cout << "Was the Patient admitted as an In-Patient or Out-Patient? ";
  47. cin >> answer;
  48. cout << endl;
  49. }
  50. //
  51. //Creates if statement In Patient Function
  52. if (answer == "in" || answer == "In" || answer == "IN") //Validates input
  53. {
  54. patient("In"); //In Patient Function
  55. }
  56. //
  57. //Creates if statement for Out Patient Function
  58. if (answer == "out" || answer == "Out" || answer == "OUT")//Validates input
  59. {
  60. patient("Out"); //Out Patient Function
  61. }
  62. return 0;
  63. }
  64.  
  65. /*******************************************************************************
  66.  * Definition of function patient. The "In" is meant to hold variables day,
  67.  * rate, charges, and services, to differentiate the overloaded
  68.  * function.
  69.  ******************************************************************************/
  70. double patient()
  71. {
  72. //
  73. //Initializing Variables
  74. double days; //Days in hospital
  75. double rate; //Cost per day in hospital
  76. double charges; //Cost of medications
  77. double services;//Cost of hospital services like xrays
  78. //
  79. //Displaying prompt
  80. cout << "Days Spent in Hospital: ";
  81. cin >> days;
  82. //
  83. //Creates input validation for days
  84. while (days < 0)
  85. {
  86. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  87. cout << "Days Spent in Hospital: ";
  88. cin >> days;
  89. }
  90. cout << "\nDaily Rate: ";
  91. cin >> rate;
  92. //
  93. //Creates input validation for rate
  94. while (rate < 0)
  95. {
  96. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  97. cout << "Daily Rate: ";
  98. cin >> rate;
  99. }
  100. cout << "\nMedicaion Charges: ";
  101. cin >> charges;
  102. //
  103. //Creates input validation for charges
  104. while (charges < 0)
  105. {
  106. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  107. cout << "Medication Charges: ";
  108. cin >> charges;
  109. }
  110. cout << "\nHospital Services: ";
  111. cin >> services;
  112. //
  113. //Creates input validation for services
  114. while (services < 0)
  115. {
  116. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  117. cout << "Hospital Services: ";
  118. cin >> services;
  119. }
  120. //
  121. //Computes total cost of hospital
  122. double total = (days * rate) + charges + services; //Adds all the charges
  123. //
  124. //Outputs results
  125. cout << fixed << setprecision(2) << "\nTotal Charges: " << total;
  126. return total;
  127. }
  128.  
  129. /*******************************************************************************
  130.  * Definition of function patient. The "Out" is meant to hold variables charges
  131.  * and services, to differentiate the overloaded function.
  132.  ******************************************************************************/
  133. double patient(string Out)
  134. {
  135. //
  136. //Initializing Variables
  137. double charges; //Charges for medication
  138. double services;//Hospital services charges
  139. //
  140. //Display promt
  141. cout << "Medicaion Charges: ";
  142. cin >> charges;
  143. //
  144. //Creating while loop for input validation
  145. while (charges < 0)
  146. {
  147. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  148. cout << "Medication Charges: ";
  149. cin >> charges;
  150. }
  151. cout << "\nHospital Services: ";
  152. cin >> services;
  153. //
  154. //Creating while loop for input validation
  155. while (services < 0)
  156. {
  157. cout << "Invalid Input. Please Enter a Valid Amount" << endl;
  158. cout << "Hospital Services: ";
  159. cin >> services;
  160. }
  161. //
  162. //Computes Out patient total
  163. double total = charges + services; //Adds all charges
  164. //
  165. //Output Results
  166. cout << fixed << setprecision(2) <<"\nTotal Charges: " << total;
  167. return total;
  168. }
Success #stdin #stdout 0s 5316KB
stdin
out 2 2
stdout
Was the Patient admitted as an In-Patient or Out-Patient? 
Medicaion Charges: 
Hospital Services: 
Total Charges: 4.00