// Marvyn Jesse De La Torre CS1A Chapter 6, p. 373, #14
//
/*************************************************************************
* CALCULATE HOSPITAL CHARGES
* This program calculates hospital charges for in-patients and out-patients.
*
* INPUT
* days, dailyRate, medication, services, patientType
*
* OUTPUT
* totalCharges: Total hospital charges
*************************************************************************/
#include <cctype>
#include <iomanip>
#include <iostream>
using namespace std;
// Function Prototypes
double calculateCharges(int days, double dailyRate, double medication,
double services);
double calculateCharges(double medication, double services);
int main()
{
char patientType;
int days;
double dailyRate, medication, services, totalCharges;
cout << "Enter I for in-patient or O for out-patient: ";
cin >> patientType;
patientType = toupper(patientType);
if (patientType == 'I')
{
cout << "Number of days in hospital: ";
cin >> days;
cout << "Daily rate: $";
cin >> dailyRate;
cout << "Medication charges: $";
cin >> medication;
cout << "Hospital service charges: $";
cin >> services;
totalCharges = calculateCharges(days, dailyRate, medication, services);
}
else
{
cout << "Medication charges: $";
cin >> medication;
cout << "Hospital service charges: $";
cin >> services;
totalCharges = calculateCharges(medication, services);
}
cout << fixed << setprecision(2);
cout << "Total hospital charges: $" << totalCharges << endl;
return 0;
}
/*************************************************************************
* calculateCharges (in-patient)
* Returns the total charges for an in-patient.
*************************************************************************/
double calculateCharges(int days, double dailyRate, double medication,
double services)
{
return days * dailyRate + medication + services;
}
/*************************************************************************
* calculateCharges (out-patient)
* Returns the total charges for an out-patient.
*************************************************************************/
double calculateCharges(double medication, double services)
{
return medication + services;
}