Question

In: Computer Science

A10 – Overloaded Hospital "Overloaded Hospital", page 371, Number 15 Write a program that computes and...

A10 – Overloaded Hospital

"Overloaded Hospital", page 371, Number 15

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. If the patient was an in-patient, the following data should be entered by the user:

The number of days spent is the hospital
The daily rate
Hospital medication charges
Charges for the hospital services (lab test, etc.)
The program should as for the following if the patient was an out-patient:

Charges for the hospital services (lab tests, etc.)
Hospital medication charges
The program should/will use two overloaded functions (defined in this chapter!) to calculate the total charges. One of the functions should accept arguments for the in-patient data, while the other functions accepts arguments for the out-patient information. Both functions should return the total charges and of course you will print these tot he screen.

Input Validation: Do not accept negative numbers for any data.

Please do not copy and paste someone elses code. It would really be awesome if someone explained the code to me.

Solutions

Expert Solution

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


Related Solutions

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 •...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ 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 inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
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...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
Design a program that asks the user for a number and the program computes the factorial...
Design a program that asks the user for a number and the program computes the factorial of that number and displays the result . Implement with two different modules - one that uses a for loop and one that uses a while loop Grading Rubrick Program Compiles Cleanly  syntax errors25 pts-5 per errorProgram runs without runtime errors ( validation)run-time errors 25 pts-5 per errorProgram give correct answersLogic errors30 pts-5 per errorProgram is repeatableNot repeatable5 pts-5 ptsProgram is well modularizedBarely Modularized10 pts-...
Write the following java program. Desc: The program computes the cost of parking a car in...
Write the following java program. Desc: The program computes the cost of parking a car in a public garage at the rate $5.00/hour. The client will always be charged for whole hours. For example, if a car parked for 2 hours and 1 minute, the client will be charged for 3 hours. Input: User inputs the entry time and exit time in 24-hr clock format (hh:mm) Output: The enter and exit times, the length of time the car is parked...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Write a program that reads in the radius and length of a cylinder and computes volume...
Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas: area = radius * radius * PI volume = area * length
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT