Overloaded Hospital
Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an in-patient or an out-patient. If the patient was an in-patient the following data should be entered:
· The number of days spent in the hospital
· The daily rate
· Charges for hospital services (lab test, etc.)
· Hospital medication charges
If the patient was an out-patient the following data should be entered:
· Charges for hospital services (lab tests, etc.)
· Hospital medication charges
The program should use two overloaded functions to calculate the total charges. One of the functions should accept arguments for the in-patient data, while the other functions accepts arguments for out-patient data. Both functions should return the total charges.
Input validation: Do not accept negative numbers for any information.
Here is what the output will look like: (Click to enlarge)
Here is the code:
// Kim Pestana, Chap. 6, Overloaded Hospital
// Write a program that computes and displays the charges for a patient’s hospital stay.
// First, the program should ask if the patient was admitted as an in-patient or an
// out-patient. If the patient was an in-patient the following data should be entered:
// • The number of days spent in the hospital
// • The daily rate
// • Charges for hospital services (lab test, etc.)
// • Hospital medication charges
// If the patient was an out-patient the following data should be entered:
// • Charges for hospital services (lab tests, etc.)
// • Hospital medication charges
// The program should use two overloaded functions to calculate the total charges.
// One of the functions should accept arguments for the in-patient data,
// while the other functions accepts arguments for out-patient data. Both functions
// should return the total charges.
// Input validation: Do not accept negative numbers for any information.
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
// Function Prototypes
double Costs(int numDays, double ratePerday, double lab, double medication);
double Costs(double lab, double medication);
int main()
{
int stay;
double totalIn;
double totalOut;
int numDays;
double ratePerday, lab, medication;
// Get choice of inpatient or outpatient hospital stay
cout << "You will need to enter a 0 for inpatient stay or a 1 for outpatient stay." << endl;
cin >> stay;
// Validate the choice
while (stay != 0 && stay != 1)
{
cout << "Please enter 0 for inpatient stay or a 1 for outpatient stay." << endl;
cin >> stay;
}
// Process selection
switch(stay)
{
// Inpatient Stay
case 0:
cout << "Please enter the number of days spent at the hospital: " << endl;
cin >> numDays;
cout << "Please enter the hospital's daily rate: " << endl;
cin >> ratePerday;
cout << "Please enter the charges for labwork: " << endl;
cin >> lab;
cout << "Please enter the charges for medications: " << endl;
cin >> medication;
totalIn = Costs(numDays, ratePerday, lab, medication);
cout << "The total inpatient costs are: $" << totalIn << endl;
break;
// Outpatient Stay
case 1:
cout << "Please enter the charges for labwork: " << endl;
cin >> lab;
cout << "Please enter the charges for medications: " << endl;
cin >> medication;
totalOut = Costs(lab, medication);
cout << "The total outpatient costs are: $" << totalOut << endl;
break;
}
system("Pause");
return 0;
}
// function for Inpatient Stay
double Costs(int numDays, double ratePerday, double lab, double medication)
{
// Calculate total inpatient costs
return (numDays * ratePerday) + lab + medication;
}
// function for Outpatient Stay
double Costs(double lab, double medication)
{
// Calculate total inpatient costs
return lab + medication;
}
No comments:
Post a Comment