//Devin Scheu CS1A Chapter 6, P. 173, #14
//
/**************************************************************
*
* CALCULATE HOSPITAL CHARGES
* ____________________________________________________________
* This program determines the total charges for a patient s
* hospital stay based on in-patient or out-patient status.
* ____________________________________________________________
* INPUT
* patientType : The type of patient (in-patient or out-patient)
* daysInHospital : The number of days for in-patient
* dailyRate : The daily rate for in-patient
* medicationCharges : Hospital medication charges
* serviceCharges : Charges for hospital services
*
* OUTPUT
* totalCharges : The total charges for the patient s stay
*
**************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Overloaded function for in-patient charges
double calculateCharges(int days, double dailyRate, double medicationCharges, double serviceCharges) {
return (days * dailyRate) + medicationCharges + serviceCharges;
}
// Overloaded function for out-patient charges
double calculateCharges(double medicationCharges, double serviceCharges) {
return medicationCharges + serviceCharges;
}
int main () {
//Variable Declarations
string patientType; //INPUT - The type of patient (in-patient or out-patient)
int daysInHospital; //INPUT - The number of days for in-patient
double dailyRate; //INPUT - The daily rate for in-patient
double medicationCharges; //INPUT - Hospital medication charges
double serviceCharges; //INPUT - Charges for hospital services
double totalCharges; //OUTPUT - The total charges for the patient s stay
//Prompt for Patient Type and Echo
cout << "Enter patient type (in-patient or out-patient): ";
cin >> patientType;
cout << patientType << endl;
//Input Validation and Data Collection
if (patientType == "in-patient" || patientType == "out-patient") {
if (patientType == "in-patient") {
cout << "Enter the number of days in hospital: ";
cin >> daysInHospital;
while (daysInHospital < 0) {
cout << "\nError: Please enter a non-negative number: ";
cin >> daysInHospital;
}
cout << daysInHospital << endl;
cout << "Enter the daily rate: $";
cin >> dailyRate;
while (dailyRate < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> dailyRate;
}
cout << dailyRate << endl;
}
cout << "Enter hospital medication charges: $";
cin >> medicationCharges;
while (medicationCharges < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> medicationCharges;
}
cout << medicationCharges << endl;
cout << "Enter charges for hospital services: $";
cin >> serviceCharges;
while (serviceCharges < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> serviceCharges;
}
cout << serviceCharges << endl;
} else {
cout << "\nError: Please enter 'in-patient' or 'out-patient': ";
cin >> patientType;
cout << patientType << endl;
// Recheck patient type after error
while (patientType != "in-patient" && patientType != "out-patient") {
cout << "\nError: Please enter 'in-patient' or 'out-patient': ";
cin >> patientType;
cout << patientType << endl;
}
// Recollect data if type was corrected
if (patientType == "in-patient") {
cout << "Enter the number of days in hospital: ";
cin >> daysInHospital;
while (daysInHospital < 0) {
cout << "\nError: Please enter a non-negative number: ";
cin >> daysInHospital;
}
cout << daysInHospital << endl;
cout << "Enter the daily rate: $";
cin >> dailyRate;
while (dailyRate < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> dailyRate;
}
cout << dailyRate << endl;
}
cout << "Enter hospital medication charges: $";
cin >> medicationCharges;
while (medicationCharges < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> medicationCharges;
}
cout << medicationCharges << endl;
cout << "Enter charges for hospital services: $";
cin >> serviceCharges;
while (serviceCharges < 0) {
cout << "\nError: Please enter a non-negative amount: $";
cin >> serviceCharges;
}
cout << serviceCharges << endl;
}
//Calculate Charges
if (patientType == "in-patient") {
totalCharges = calculateCharges(daysInHospital, dailyRate, medicationCharges, serviceCharges);
} else {
totalCharges = calculateCharges(medicationCharges, serviceCharges);
}
//Separator and Output Section
cout << "-------------------------------------------------------" << endl;
cout << "OUTPUT:" << endl;
//Output Result
cout << fixed << setprecision(2);
if (patientType == "in-patient") {
cout << left << setw(25) << "Days in Hospital:" << right << setw(15) << daysInHospital << endl;
cout << left << setw(25) << "Daily Rate:" << right << setw(15) << "$" << dailyRate << endl;
}
cout << left << setw(25) << "Medication Charges:" << right << setw(15) << "$" << medicationCharges << endl;
cout << left << setw(25) << "Service Charges:" << right << setw(15) << "$" << serviceCharges << endl;
cout << left << setw(25) << "Total Charges:" << right << setw(15) << "$" << totalCharges << endl;
} //end of main()