Assignment 8, Chapter 5 write a program that computes and displays the charges f
ID: 3817320 • 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
1)
#include<iostream>
using namespace std;
class patients //defining patient class
{
private: //private members can only accessed by its class members only
int c; //variable to store the type to patient
int no_days=0; //variable to store number of days spend in the hospital
float daily_rate=0.0; //variable to store daily rates of the hospital
float hosp_srv_chrg; //variable to store charges of the hospital services
float hosp_med_chrg; //variable to store hospital medication charges
float tot_chrg; //variable to store total charges
void validation_ip() //function to get a valid input from patient
{
while(1)
{
if(no_days<0)
{
cout<<"Re-entered the number of days spend in the hospital"<<endl;
cin>>no_days;
}
else
break; //break when input is grater then zero that is valid input
}
while(1)
{
if(daily_rate<0)
{
cout<<"Re-entered the daily rates of the hospital"<<endl;
cin>>daily_rate;
}
else
break;
}
while(1)
{
if(hosp_srv_chrg<0)
{
cout<<"Re-entered the charges of the hospital services"<<endl;
cin>>hosp_srv_chrg;
}
else
break;
}
while(1)
{
if(hosp_med_chrg<0)
{
cout<<"Re-entered the hospital medication charges"<<endl;
cin>>hosp_med_chrg;
}
else
break;
}
if(c==1)
total_chrg(no_days,daily_rate,hosp_srv_chrg,hosp_med_chrg);
else
total_chrg(hosp_srv_chrg,hosp_med_chrg);
}
void total_chrg(int no_days,float daily_rate,float hosp_srv_chrg,float hosp_med_chrg) //overload function to calculate total charges of inpatient type of patient
{
tot_chrg=no_days*daily_rate+hosp_srv_chrg+hosp_med_chrg;
cout<<"Total charges="<<tot_chrg;
}
void total_chrg(float hosp_srv_chrg,float hosp_med_chrg) //overload function to calculate total charges of outpatient type of patient
{
tot_chrg=hosp_srv_chrg+hosp_med_chrg;
cout<<"Total charges="<<tot_chrg;
}
public: // public members cab be accessed by class members as well as out side functions
void choice()
{
cout<<"choice:Are you admitted as an (1) inpatient (2)Outpatient"<<endl;
cin>>c;;
}
void input()
{
if(c==1)
{
cout<<"Enter the number of days spend in the hospital"<<endl;
cin>>no_days;
cout<<"Enter the daily rates of the hospital"<<endl;
cin>>daily_rate;
}
cout<<"Enter the charges of the hospital services"<<endl;
cin>>hosp_srv_chrg;
cout<<"Enter hospital medication charges"<<endl;
cin>>hosp_med_chrg;
validation_ip();
}
};
int main()
{
patients p; //creating object of patient
p.choice(); //calling choice function for patient object p
p.input(); //calling choice function for patient object p
return 0;
}