fork download
  1. // Marvyn Jesse De La Torre CS1A Chapter 6, p. 373, #14
  2. //
  3. /*************************************************************************
  4.  * CALCULATE HOSPITAL CHARGES
  5.  * This program calculates hospital charges for in-patients and out-patients.
  6.  *
  7.  * INPUT
  8.  * days, dailyRate, medication, services, patientType
  9.  *
  10.  * OUTPUT
  11.  * totalCharges: Total hospital charges
  12.  *************************************************************************/
  13.  
  14. #include <cctype>
  15. #include <iomanip>
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. // Function Prototypes
  20. double calculateCharges(int days, double dailyRate, double medication,
  21. double services);
  22. double calculateCharges(double medication, double services);
  23.  
  24. int main()
  25. {
  26. char patientType;
  27. int days;
  28. double dailyRate, medication, services, totalCharges;
  29.  
  30. cout << "Enter I for in-patient or O for out-patient: ";
  31. cin >> patientType;
  32. patientType = toupper(patientType);
  33.  
  34. if (patientType == 'I')
  35. {
  36. cout << "Number of days in hospital: ";
  37. cin >> days;
  38.  
  39. cout << "Daily rate: $";
  40. cin >> dailyRate;
  41.  
  42. cout << "Medication charges: $";
  43. cin >> medication;
  44.  
  45. cout << "Hospital service charges: $";
  46. cin >> services;
  47.  
  48. totalCharges = calculateCharges(days, dailyRate, medication, services);
  49. }
  50. else
  51. {
  52. cout << "Medication charges: $";
  53. cin >> medication;
  54.  
  55. cout << "Hospital service charges: $";
  56. cin >> services;
  57.  
  58. totalCharges = calculateCharges(medication, services);
  59. }
  60.  
  61. cout << fixed << setprecision(2);
  62. cout << "Total hospital charges: $" << totalCharges << endl;
  63.  
  64. return 0;
  65. }
  66.  
  67. /*************************************************************************
  68.  * calculateCharges (in-patient)
  69.  * Returns the total charges for an in-patient.
  70.  *************************************************************************/
  71. double calculateCharges(int days, double dailyRate, double medication,
  72. double services)
  73. {
  74. return days * dailyRate + medication + services;
  75. }
  76.  
  77. /*************************************************************************
  78.  * calculateCharges (out-patient)
  79.  * Returns the total charges for an out-patient.
  80.  *************************************************************************/
  81. double calculateCharges(double medication, double services)
  82. {
  83. return medication + services;
  84. }
Success #stdin #stdout 0.01s 5316KB
stdin
I 3 450 125.50 230
stdout
Enter I for in-patient or O for out-patient: Number of days in hospital: Daily rate: $Medication charges: $Hospital service charges: $Total hospital charges: $1705.50