In: Computer Science
Thanks for the question.
Here is the completed code for this problem in C++
Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the
answer. Thanks!
=================================================================
#include<iostream>
#include<string>
using namespace std;
// function accepts the message to be displayed
// function keeps on prompting user for a non-negative number
double get_value(string message){
double value;
do{
cout<<message;
cin>>value;
if(value<0){
cout<<"Value cannot be less than zero.\n";
}
}while(value<0);
return value;
}
// below are the two overloaded functions
// for in patients
double getCharges(double days, double daily_rate, double
med_charges, double service_charges){
// calculate total charges and return the total amount
in one line
return days*daily_rate + med_charges +
service_charges;
}
// for out patients
double getCharges(double med_charges, double
service_charges){
return med_charges+service_charges;
}
// function prompts for valid patient type
// until user enter either I or O
void get_choice(char &letter){
do{
cout<<"Enter your choice (I
for in-patient O for out-patient): ";
cin>>letter;
}while(letter!='I' && letter!='O');
}
int main(){
char patient_type;
double days; double
rate,med_charges,service_charges;
get_choice(patient_type);
// when patient is in patient we ask for days and rate
also
if(patient_type=='I'){
days = get_value("Enter the number
of days spent in hospital: ");
rate = get_value("Enter the daily
rate: ");
}
// med and services charges are common for both
types
med_charges=get_value("Enter the hospital medication
charges: ");
service_charges=get_value("Enter the hospital service
charges: ");
double total_charges=0.0;
// when in patient we call getCharges with 4
parameters
if(patient_type=='I')
{
total_charges =
getCharges(days,rate,med_charges,service_charges);
}else{
// if out paitent we call
getCharges with only two parameters
total_charges =
getCharges(med_charges,service_charges);
}
// out put the total charges
cout<<"Total Charges:
$"<<total_charges<<endl;
}
========================================================================

Thanks, let me know for any questions or in case you encounter any issue.
Please do give a thumbs up from your end : )