2. Write a program that computes and displays the charges for a patient\'s hospi
ID: 3741503 • Letter: 2
Question
2. 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 out-patient if the patient was an in patient, the following information should be requested number of days spent in the hospital the daily rate hospital medication charges charges for hospital services (lab test, etc.) If the was an out patient, the following information should be requested: charges for hospital services (lab test, etc.) hospital medication charges The program should use two methods to calculate the total charges. One of the methods should accept arguments for the in-patient information, while method accepts argument for out-patient information. Both methods should return the total charges. ?Explanation / Answer
#include <iostream>
using namespace std;
double totalChargesInPatient()
{
int days;
double rate,medCharges,serviceCharges;
cout<<" Enter number of days spent in the hospital : ";
cin>>days;
cout<<" Enter daily rate : ";
cin>>rate;
cout<<" Enter hospital medication charges : ";
cin>>medCharges;
cout<<" Enter charges for hospital services : ";
cin>>serviceCharges;
return (days*rate +medCharges+serviceCharges);
}
double totalChargesOutPatient()
{
double medCharges,serviceCharges;
cout<<" Enter hospital medication charges : ";
cin>>medCharges;
cout<<" Enter charges for hospital services : ";
cin>>serviceCharges;
return (medCharges+serviceCharges);
}
int main() {
int option;
cout<<"Enter option the patient was admitted as in-patient(option = 1) or out-patient(option = 2) : ";
cin>>option;
if(option == 1) // call method for in-patient or out-patient
cout<<" Total Charges $: "<<totalChargesInPatient();
else if(option == 2)
cout<<" Total Charges $: "<<totalChargesOutPatient();
else
cout<<" Invalid option ";
return 0;
}
Output:
Enter option the patient was admitted as in-patient(option = 1) or out-patient(option = 2) :1
Enter number of days spent in the hospital :4
Enter daily rate :100.80
Enter hospital medication charges :56.78
Enter charges for hospital services :200.67
Enter option the patient was admitted as in-patient(option = 1) or out-patient(option = 2) :2
Enter hospital medication charges :127.78
Enter charges for hospital services :134.50
Total Charges $: 262.28
Do ask if any doubt. Please upvote.
Total Charges $: 660.65
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.