Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 8, Chapter 5 write a program that computes and displays the charges f

ID: 3817317 • Letter: A

Question

Assignment 8, Chapter 5 write a program that computes and displays the charges for a patient's hospital an stay. First, the program should ask if the patient was admitted as an inpatient or outpatient. the an inpatient, the following data should be entered: .The number of days spent in the hospital The daily rate Charges for hospital services (lab tests, etc.) Hospital medication charges If the patient was an outpatient, the following data should be entered: .Charges for hospital services (lab tests, etc.) .Hospital medication charges Use a single, separate function to validate that no input is less than zero. If it is, it should be reentered before being returned. Once the required data has been input and validated, the program should use two overloaded functions to calculate the total charges. One of the functions should accept arguments for the inpatient data, while the other function accepts arguments for outpatient data. Both functions should return the total charges. Modify Program, overloaded Hospital, to write the report it creates to a file.

Explanation / Answer

#include <iostream>

using namespace std;

// inpatient
double calcTotalCharges(int days, double dailyRate, double hospitalServiceCharges, double medicationCharges)
{
return days*dailyRate + hospitalServiceCharges + medicationCharges;
}

// outpatient
double calcTotalCharges(double hospitalServiceCharges, double medicationCharges)
{
return hospitalServiceCharges + medicationCharges;
}

int main()
{
int patientType;
while(true)
{
cout << "Please enter 1. for impatient 2. For outPatient." << endl;
cin >> patientType;
if (patientType != 1 && patientType != 2 )
{
cout << "Please choose from given options." << endl;
}
else
{
break;
}
}
  
if (patientType == 1)
{
int days;
double dailyRate, hospitalServiceCharges, medicationCharges;
cout << "Number of days spent in hospital: ";
cin >> days;
  
cout << "Daily rate: ";
cin >> dailyRate;
  
cout << "Hospital service charges: ";
cin >> hospitalServiceCharges;
  
cout << "medication charges: ";
cin >> medicationCharges;
  
cout << "total charges are: $" << calcTotalCharges(days, dailyRate, hospitalServiceCharges, medicationCharges);
cout << endl;
}
else
{
double hospitalServiceCharges, medicationCharges;
cout << "Hospital service charges: ";
cin >> hospitalServiceCharges;
  
cout << "medication charges: ";
cin >> medicationCharges;
  
cout << "total charges are: $" << calcTotalCharges(hospitalServiceCharges, medicationCharges);
cout << endl;
}

return 0;
}

(haven't included validate function as thats what you asked No need to do a function because did not take it. )