Question

In: Computer Science

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 an outpatient:

  • Charges for hospital services (lab tests, etc.)
  • Hospital medication charges


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 information. Both functions should return the total charges.

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

Solutions

Expert Solution

#include <iostream>
using namespace std;

float total_charge(int n,float daily_rate,float med_charge,float hosp_service) // function to compute total charges
{
return n * daily_rate + med_charge + hosp_service;
}

float total_charge(float med_charge,float hosp_service) // overloading the above function with two arguments
{
return med_charge + hosp_service;
}

int main()
{
char patient_type; // it stores patient type
int n; // number of days spent in hospital
float daily_rate, med_charge, hosp_service;
  
cout << "Patient was admitted as an inpatient or an outpatient ? " << endl;
cout << "Press I for inpatient or O for outpatient : ";
cin >> patient_type;
  
if (patient_type == 'I' || patient_type == 'i') // if patient is inpatient
{
while (1){
cout << "Enter number of days spent in the hospital : ";
cin >> n;
if (n < 0)
cout << "Invalid Input! try again..." << endl; // if input is negative then ask user again to enter value
else // else if input is correct then go out of loop
break;
}
  
while (1){
cout << "Enter daily rate : ";
cin >> daily_rate;
if (daily_rate < 0)
cout << "Invalid Input! try again..." << endl;
else
break;
}
  
while (1){
cout << "Enter hospital medication charges : ";
cin >> med_charge;
if (med_charge < 0)
cout << "Invalid Input! try again..." << endl;
else
break;
}
  
while (1){
cout << "Enter charges for hospital services (lab tests, etc.) : ";
cin >> hosp_service;
if (hosp_service < 0)
cout << "Invalid Input! try again..." << endl;
else
break;
}
  
cout << "Total charges : " << total_charge(n,daily_rate,med_charge,hosp_service); // call function to compute total charge
  
}
  
else if(patient_type == 'O' || patient_type == 'o') // if patient is outpatient
{
while (1){
cout << "Enter charges for hospital services (lab tests, etc.) : ";
cin >> hosp_service;
if (hosp_service < 0)
cout << "Invalid Input! try again..." << endl;
else
break;
}
  
while (1){
cout << "Enter hospital medication charges : ";
cin >> med_charge;
if (med_charge < 0)
cout << "Invalid Input! try again..." << endl;
else
break;
}
  
cout << "Total charges : " << total_charge(med_charge,hosp_service); // call overloaded function to compute total charge
}
  
return 0;
}
output 1 :

output 2:

output 3:


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 •...
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...
Write a C++ program that displays the current time
Write a C++ program that displays the current time
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
write in c plus plus Write a program that computes the sum of the odd numbers...
write in c plus plus Write a program that computes the sum of the odd numbers and the sum of the even numbers between two values a and b. For example a=1 and b=10
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
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...
Write a C++ program that requires the user to type in an integer M and computes...
Write a C++ program that requires the user to type in an integer M and computes the function y(M) which is defined by y(0)=2, y(1)=1, y(m+1)=y(m)+2*y(m-1).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT