In: Computer Science
C++
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. Please keep asking the user until the user enters the valid choice. Please refer to the test cases for more details. 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 tests, 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. Use a single, separate function to validate that no input is less than zero. If it is, it should be re-entered before being returned. Keep validating the data until the user enters valid value. 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 in-patient data, while the other function accepts arguments for out- patient data. Both functions should return the total charges.
Test case Test Case1: Do you want to calculate the total hospital bill for (I) an In-Patient, or (O) an Out-Patient?I How many days were spent in the hospital? 10 What is the hospital daily rate? $200 What were the charges for hospital services (lab tests, etc.)? $300 What were the hospital medication charges? $50 Total Hospital Charges: $2350.00 Test Case 2: Do you want to calculate the total hospital bill for (I) an In-Patient, or (O) an Out-Patient?A Enter I or O: A Enter I or O: B Enter I or O: C Enter I or O: o What were the charges for hospital services (lab tests, etc.)? $-30 Number must be a positive number : 30 What were the hospital medication charges? $300 Total Hospital Charges: $330.00
my code #include #include using namespace std; void In_Patient_Total(int days, double rate,double service, double medication); void Out_Patient_Total(double service,double medication); int main() { char Choise; int days; double rate, service, medication; cout << "Do you want to calculate the total hospital bill for \n(I)an In - Patient, or \n(O)an Out - Patient ? "; cin >> Choise; while (Choise != 'I' && Choise != 'i' && Choise != 'o' && Choise != 'O') { cout << "Enter I or O: "; cin >> Choise; } if (Choise == 'I' || Choise == 'i') { cout << "How many days were spent in the hospital? \n"; cin >> days; while (days < 0); cout << "Number must be a positive number : "; cin >> days; cout << "What is the hospital daily rate? $\n"; cin >> rate; while (rate < 0); cout << "Number must be a positive number : "; cin >> rate; cout << "What were the charges for hospital services (lab tests, etc.)? $\n"; cin >> service; while (service < 0); cout << "Number must be a positive number : "; cin >> service; cout << "What were the hospital medication charges? $\n"; cin >> medication; while (medication < 0); cout << "Number must be a positive number : "; cin >> days; In_Patient_Total(int days, double rate, double service, double medication); } if (Choise == 'O' || Choise == 'o') { cout << "What were the charges for hospital services (lab tests, etc.)? $\n"; cin >> medication; while (medication < 0); cout << "Number must be a positive number : "; cin >> days; cout << "What were the hospital medication charges? $\n"; cin >> service; while (service < 0); cout << "Number must be a positive number : "; cin >> service; } } void In_Patient_Total(int days, double rate, double service, double medication) { return (days * rate) + (service, medication); } void Out_Patient_Total(double service, double medication) { return (service + medication); }
Code to copy along with screenshots are provided
If you have any doubts or issues, feel free to ask in comments
Please refer to screenshots for indents
Please give this answer a like, or upvote . This will be very helpful for me.
==================================================
Screenshots of code:
Screenshots of output:
Code to copy:
#include <iostream>
using namespace std;
double In_Patient_Total(int days, double rate,double service,
double medication);
double Out_Patient_Total(double service,double medication);
int isdaysNegative(int value);
double isNegative(double value);
int main()
{
// declaring required variables
char Choise;
int days;
double rate, service, medication, total;
// taking input for choosing whether patient is in or out
type
cout << "Do you want to calculate the total hospital bill for
\n(I)an In - Patient, or \n(O)an Out - Patient ? \n";
cout << "Enter I or O: ";
cin >> Choise;
// looping until user enters valid choice
while (true)
{
if(Choise == 'i' || Choise == 'I' || Choise == 'o' || Choise ==
'O')
{
// stop asking for input if user enters i,I,o or O
break;
}
else
{
cout << "Enter I or O: ";
cin >> Choise;
}
}
if (Choise == 'I' || Choise == 'i')
{
cout << "How many days were spent in the hospital? \n";
cin >> days;
// checking whether input by user is not less than 0
days = isdaysNegative(days);
cout << "What is the hospital daily rate? \n$";
cin >> rate;
// checking whether input by user is not less than 0
rate = isNegative(rate);
cout << "What were the charges for hospital services (lab
tests, etc.)? \n$";
cin >> service;
// checking whether input by user is not less than 0
service = isNegative(service);
cout << "What were the hospital medication charges?
\n$";
cin >> medication;
// checking whether input by user is not less than 0
medication = isNegative(medication);
total = In_Patient_Total(days, rate, service, medication);
}else if (Choise == 'O' || Choise == 'o')
{
cout << "What were the charges for hospital services (lab
tests, etc.)? \n$";
cin >> service;
// checking whether input by user is not less than 0
service = isNegative(service);
cout << "What were the hospital medication charges?
\n$";
cin >> medication;
// checking whether input by user is not less than 0
medication = isNegative(medication);
total = Out_Patient_Total(service, medication);
}
else
{
}
cout<<"\n\n Total Hospital Charges : $"<<total<<endl;
return 0;
}
// separate function for taking days input until input is not less
than zero
int isdaysNegative(int value)
{
while (value < 0)
{
cout << "Number must not be a negative number : ";
cin >> value;
}
return value;
}
// separate function for taking input until input is not less than
zero
double isNegative(double value)
{
while (value < 0)
{
cout << "Number must not be a negative number : ";
cin >> value;
}
return value;
}
// function to return total in case of in patient
double In_Patient_Total(int days, double rate, double service,
double medication)
{
return ( (days * rate) + service + medication );
}
// function to return total in case of out patient
double Out_Patient_Total(double service, double medication)
{
return (service + medication);
}
----------------------------------------------------------------------