Question

In: Computer Science

C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital...

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); }

Solutions

Expert Solution

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);

}
----------------------------------------------------------------------


Related Solutions

write a program that computes and displays the number of days that have elapsed between January...
write a program that computes and displays the number of days that have elapsed between January 1, 1900 and today (the day the program is run). The program must be designed as follows: Within a class named Elapsed_Days, provide the following functions: • bool is_year_valid(long year) returns true if year is >= 1900; otherwise false • bool is_month_valid(long month) returns true if month is between 1 and 12 (inclusive); otherwise false • bool is_leap_year(long year) returns true if year is...
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
In the space provided below write a C++ program that computes the total cost of books...
In the space provided below write a C++ program that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as...
In the space provided below write a C program that computes the total cost of items...
In the space provided below write a C program that computes the total cost of items you want to order online. It does so by first asking how many items are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day...
In the space provided below write a C program that computes the total amount of money...
In the space provided below write a C program that computes the total amount of money you have stored in your piggy bank. Your program does this by asking you for number of pennies, nickels, dimes, and quarters in the piggy bank and then displays how much money in total is in the piggy bank.
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT