Question

In: Computer Science

Divide by classes. Parameters and return types of each function and class member function should be...

  • Divide by classes.
  • Parameters and return types of each function and class member function should be decided in advance.

Write a program that computes a patient's bill for a hospital stay. The different components are:

  • PatientAccount Class
  • Surgery Class
  • Pharmacy Class
  • main program

Patient Account will keep total of the patient's charges. Keep track of the number of days spent in the hospital. Group must decide on hospital's daily rate.

Surgery class will have stored within it the charges for at least five types of surgery. It an update the charges variable of the PatientAccount class.

Pharmacy class will have stored within it the price of at least five types of medication. It can update the charges variable of the PatientAccount class.

Student who designs main will design a menu that allows user to enter a type of surgery and type of medication and check the patient out of the hospital. When patient checks out, the total charges should be displayed.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

#include <iostream>
#include <string>
using namespace std;

// Abstract Class PatientAccount definition
class PatientAccount
{
// Data member to store patient information
string patientName;
int days;
double daysCharge;
double amount;
public:
// Parameterized constructor to initialize data member
PatientAccount(string na, int day)
{
patientName = na;
amount = 0;
days = day;
daysCharge = 0;
}// End of parameterized constructor

// Function to return patient name
string getPatientName()
{
return patientName;
}// End of function

// Function to return amount to be paid
double getAmount()
{
return amount;
}// End of function

// Function to set patient name
void setPatientName(string na)
{
patientName = na;
}// End of function

// Function to set amount to be paid
void setAmount(double amt)
{
amount = amt;
}// End of function

// Function to return number of days stayed
int getDays()
{
return days;
}// End of function

// Function to set number of days stayed
void setDays(int day)
{
days = day;
}// End of function

// Function to return days charge
double getDaysCharge()
{
return daysCharge;
}// End of function

// Function to set days charge
void setDaysCharge(int dayCharge)
{
daysCharge = dayCharge;
}// End of function

// Prototype of pure virtual functions
virtual void display() = 0;
virtual void calculateAmount() = 0;
};// End of class

// Class Surgery derived from PatientAccount class
class Surgery : public PatientAccount
{
// Data member to store surgery information
string surgeryTypes;
double surgeryAmt;
public:
// Parameterized constructor to initialize data member
// Calls the base class parameterized constructor and passes name and days
Surgery(string na, int day, string type) : PatientAccount(na, day)
{
surgeryTypes = type;
surgeryAmt = 0;
}// End of parameterized constructor

// Function to return surgery type
string getSurgeryType()
{
return surgeryTypes;
}// End of function

// Function to set surgery type
void setSurgeryType(string type)
{
surgeryTypes = type;
}// End of function

// Function to return surgery amount
double getSurgeryAmount()
{
return surgeryAmt;
}// End of function

// Function to set surgery amount
void setSurgeryAmount(double amt)
{
surgeryAmt = amt;
}// End of function

// Overrides display() function to display patient with surgery information
void display()
{
cout<<"\n Patient Name: "<<getPatientName();
cout<<"\n Number of days: "<<getDays()<<"\t Days Charge: "<<getDaysCharge();
cout<<"\n Surgery Type: "<<surgeryTypes<<"\t Surgery Charge: "<<surgeryAmt;
cout<<"\n Amount to be paid: "<<getAmount();
}// End of function

// Overrides calculateAmount() function to calculate amount to be paid
void calculateAmount()
{
// Checks if surgeryTypes is "Cataract"
if(surgeryTypes.compare("Cataract"))
// Update surgery amount by adding 1000 as surgery charge
surgeryAmt += 1000;
// Otherwise checks if surgeryTypes is "Dental"
else if(surgeryTypes.compare("Dental"))
// Update surgery amount by adding 500 as surgery charge
surgeryAmt += 500;
// Otherwise checks if surgeryTypes is "Breast"
else if(surgeryTypes.compare("Breast"))
// Update surgery amount by adding 2000 as surgery charge
surgeryAmt += 2000;
// Otherwise type of surgery is "Endocrine"
else
// Update surgery amount by adding 3000 as surgery charge
surgeryAmt += 3000;
// Calls the function setDaysCharge() to set days charge
// Calls the getDays() to get number of days and multiply 100 as daily charge
setDaysCharge(getDays() * 100);
// Calls setAmount() to set the total amount
// Calls getAmount() to get the current amount and adds surgery amount to it
setAmount(getAmount() + surgeryAmt);
// Calls setAmount() to set the total amount
// Calls getAmount() to get the current amount and adds days charges by calling the function getDaysCharge()
setAmount(getAmount() + getDaysCharge());
}// End of function
};// End of Surgery class

// Class Pharmacy derived from PatientAccount class
class Pharmacy : public PatientAccount
{
// Data member to store pharmacy information
string medicationName;
double medicationAmount;
public:
// Parameterized constructor to initialize data member
// Calls the base class parameterized constructor and passes name and days
Pharmacy(string na, int day, string name) : PatientAccount(na, day)
{
medicationName = name;
medicationAmount = 0;
}// End of parameterized constructor

// Function to return Medication Name
string getMedicationName()
{
return medicationName;
}// End of function

// Function to set Medication Name
void setMedicationName(string name)
{
medicationName = name;
}// End of function

// Function to return Medication amount
double getMedicationAmount()
{
return medicationAmount;
}// End of function

// Function to set Medication amount
void setMedicationAmount(double amt)
{
medicationAmount = amt;
}// End of function

// Overrides display() function to display patient with pharmacy information
void display()
{
cout<<"\n Patient Name: "<<getPatientName();
cout<<"\n Number of days: "<<getDays()<<"\t Days Charge: "<<getDaysCharge();
cout<<"\n Medication Name: "<<medicationName<<"\t Medication Charge: "<<medicationAmount;
cout<<"\n Amount to be paid: "<<getAmount();
}// End of function

// Overrides calculateAmount() function to calculate amount to be paid
void calculateAmount()
{
// Checks if medicationName is "Acetaminophen"
if(medicationName.compare("Acetaminophen"))
// Update medicationAmount by adding 300 as medication charge
medicationAmount += 300;
// Otherwise checks if medicationName is "Cymbalta"
else if(medicationName.compare("Cymbalta"))
// Update medicationAmount by adding 200 as medication charge
medicationAmount += 200;
// Otherwise checks if medicationName is "Doxycycline"
else if(medicationName.compare("Doxycycline"))
// Update medicationAmount by adding 100 as medication charge
medicationAmount += 500;
// Otherwise type of surgery is "Loratadine"
else
// Update medicationAmount by adding 700 as medication charge
medicationAmount += 700;

// Calls the function setDaysCharge() to set days charge
// Calls the getDays() to get number of days and multiply 100 as daily charge
setDaysCharge(getDays() * 100);
// Calls setAmount() to set the total amount
// Calls getAmount() to get the current amount and adds medication amount to it
setAmount(getAmount() + medicationAmount);
// Calls setAmount() to set the total amount
// Calls getAmount() to get the current amount and adds days charges by calling the function getDaysCharge()
setAmount(getAmount() + getDaysCharge());
}// End of function
};// End of Pharmacy class

------------------------------------------------------------------------------------------------

#include <iostream>
#include <string>
#include <stdlib.h>
#include "PatientAccount.cpp"
using namespace std;

// Function to display main men, accepts user choice and returns choice
int mainMenu()
{
// To store choice
int ch;
// Display menu
cout<<"\n 1 Surgery.";
cout<<"\t 2 Pharmacy.";
cout<<"\t 3 Exit.";
// Accepts user choice
cout<<"\n Enter your choice: ";
cin>>ch;
// Returns user choice
return ch;
}// End of function

// Function to display surgery men, accepts user choice and returns choice
int SurgeryMenu()
{
// To store choice
int ch;
// Loops till valid user choice
do
{
// Display menu
cout<<"\n 1 Cataract.";
cout<<"\t 2 Dental.";
cout<<"\t 3 Breast.";
cout<<"\t 4 Endocrine.";
// Accepts user choice
cout<<"\n Enter your choice: ";
cin>>ch;
// Checks if the choice is between 1 and 4 inclusive then come out of the loop
if(ch >= 1 && ch <= 4)
break;
// Otherwise invalid choice
else
cout<<"\n Invalid Surgery Type. Try again.";
}while(1); // End of do - while loop
// Returns user choice
return ch;
}// End of function

// Function to display pharmacy men, accepts user choice and returns choice
int PharmacyMenu()
{
// To store choice
int ch;
// Loops till valid user choice
do
{
// Display menu
cout<<"\n 1 Acetaminophen.";
cout<<"\t 2 Cymbalta.";
cout<<"\t 3 Doxycycline.";
cout<<"\t 4 Loratadine.";
// Accepts user choice
cout<<"\n Enter your choice: ";
cin>>ch;
// Checks if the choice is between 1 and 4 inclusive then come out of the loop
if(ch >= 1 && ch <= 4)
break;
// Otherwise invalid choice
else
cout<<"\n Invalid Medication Type. Try again.";
}while(1); // End of do - while loop
// Returns user choice
return ch;
}// End of function

int main()
{
Pharmacy *p = NULL;
Surgery *s = NULL;
string SurgeryType[] = {"Cataract", "Dental", "Breast", "Endocrine"};
string medicationName[] = {"Acetaminophen", "Cymbalta", "Doxycycline", "Loratadine"};
string name;
int day, type;
do
{
// Calls the main menu() to display main menu, accept user choice and return user choice
// Based on the return value creates appropriate class object
switch(mainMenu())
{
case 1:
// Accepts data from user
cout<<"\n Enter Patient name: ";
cin>>name;
cout<<"\n Enter Number of days stayed in hospital: ";
cin>>day;
cout<<"\n Enter Surgery Type: ";
// Calls the function to display surgery menu, accepts user choice and return user choice
type = SurgeryMenu();
// Creates an surgery object
s = new Surgery(name, day, SurgeryType[type-1]);
// Calls the function to calculate amount
s->calculateAmount();
// Calls the function to display surgery information
s->display();
break;
case 2:
// Accepts data from user
cout<<"\n Enter Patient name: ";
cin>>name;
cout<<"\n Enter Number of days stayed in hospital: ";
cin>>day;
cout<<"\n Enter Medication Type: ";
// Calls the function to display pharmacy menu, accepts user choice and return user choice
type = PharmacyMenu();
// Creates an pharmacy object
p = new Pharmacy(name, day, medicationName[type-1]);
// Calls the function to calculate amount
p->calculateAmount();
// Calls the function to display pharmacy information
p->display();
break;
case 3:
exit(0);
default:
cout<<"\n Invalid choice.";
}// End of switch - case
}while(1); // End of do - while loop
}// End of main function

Sample Output:

1 Surgery. 2 Pharmacy. 3 Exit.
Enter your choice: 1

Enter Patient name: Ram

Enter Number of days stayed in hospital: 10

Enter Surgery Type:
1 Cataract. 2 Dental. 3 Breast. 4 Endocrine.
Enter your choice: 2

Patient Name: Ram
Number of days: 10 Days Charge: 1000
Surgery Type: Dental Surgery Charge: 1000
Amount to be paid: 2000
1 Surgery. 2 Pharmacy. 3 Exit.
Enter your choice: 5

Invalid choice.
1 Surgery. 2 Pharmacy. 3 Exit.
Enter your choice: 2

Enter Patient name: Sunita

Enter Number of days stayed in hospital: 5

Enter Medication Type:
1 Acetaminophen. 2 Cymbalta. 3 Doxycycline. 4 Loratadine.
Enter your choice: 7

Invalid Medication Type. Try again.
1 Acetaminophen. 2 Cymbalta. 3 Doxycycline. 4 Loratadine.
Enter your choice: 3

Patient Name: Sunita
Number of days: 5 Days Charge: 500
Medication Name: Doxycycline Medication Charge: 300
Amount to be paid: 800
1 Surgery. 2 Pharmacy. 3 Exit.
Enter your choice: 3


Related Solutions

This program should be designed in group. Divide by classes. Parameters and return types of each...
This program should be designed in group. Divide by classes. Parameters and return types of each function and class member function should be decided in advance. Write a program that computes a patient's bill for a hospital stay. The different components are: PatientAccount Class Surgery Class Pharmacy Class main program Patient Account will keep total of the patient's charges. Keep track of the number of days spent in the hospital. Group must decide on hospital's daily rate. Surgery class will...
white a class having two private variables and one member function which will return the area...
white a class having two private variables and one member function which will return the area of rectangle
Write two classes Class A and Class B in class A you should read from the...
Write two classes Class A and Class B in class A you should read from the keyboard a number and you should call a public method of the class B that will print on the screen whether the number that was read from the keyboard in class A is multiple of 7 and has the last digit 5.
Make a class diagram (static structure with classes, interfaces and their relationship). It should include classes,...
Make a class diagram (static structure with classes, interfaces and their relationship). It should include classes, major attributes, major methods, class associations and multiplicities. The details of the project and its functional requirements are: Develop a sentiment analysis system for product rating. It is an e-commerce web application. The main objective of this sentiment analysis system is to understand the hidden sentiments of customers in feedback and comments and analyze their product rating patterns. When registered customers (they can create...
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and...
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters.
// If you modify any of the given code, the return types, or the parameters, you...
// If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // You are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of employees struct employeeList {    struct employee* employee;    struct employeeList* next; } *list = NULL;              ...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool. It will...
Write a function in R named counts. This function should take as parameters a numeric vector...
Write a function in R named counts. This function should take as parameters a numeric vector x and also a number indicating a number of bins n. The function will consider the range [min(x),max(x)], and then consider a parti- tion of this interval into n non-overlapping equally sized half open intervals: I1 = [min(x),b1),I2 = [b1,b − 2),...,In = (bn−1,max(x)]. Note that since the intervals are equally sized, the value of bi is constrained. The function will then return a...
C++ Classes & Objects Create a class named Student that has three private member: string firstName...
C++ Classes & Objects Create a class named Student that has three private member: string firstName string lastName int studentID Write the required mutator and accessor methods/functions (get/set methods) to display or modify the objects. In the 'main' function do the following (1) Create a student object "student1". (2) Use set methods to assign StudentID: 6337130 firstName: Sandy lastName: Santos (3) Display the students detail using get functions in standard output using cout: Sandy Santos 6337130
Part 1 1. Implement the binary search function. The function should take as formal parameters an...
Part 1 1. Implement the binary search function. The function should take as formal parameters an array of integers, its size and target, and returns (a) in the case of successful search – the position (index) of the target in the array (b) in the case of unsuccessful search – an exception with the message “Unsuccessful search” thrown from the function to the user. 2. The binary search works correctly only when the input is sorted. This requirement should be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT