Question

In: Computer Science

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 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.

C++

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

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...
The following divide-and-conquer algorithm is designed to return TRUE if and only if all elements of...
The following divide-and-conquer algorithm is designed to return TRUE if and only if all elements of the array have equal values. For simplicity, suppose the array size is n=2k for some integer k. Input S is the starting index, and n is the number of elements starting at S. The initial call is SAME(A, 0, n). Boolean SAME (int A[ ], int S, int n) { Boolean T1, T2, T3; if (n == 1) return TRUE; T1 = SAME (A,...
// 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;              ...
A java program with classes and methods to manage employment. Program should be able to store/add...
A java program with classes and methods to manage employment. Program should be able to store/add employees, calculate payroll, display or schedule shifts. All classes should have at least a null constructor and copy constructor. Other constructors are up to your discretion. Include all necessary accessors and modifiers. To test the classes, create a container class with simply a main() method. The container class will have attributes that are class objects of each of the classes you create. The main()...
Consider three classes, each consisting of 20 students. From this group of 60 students, a group...
Consider three classes, each consisting of 20 students. From this group of 60 students, a group of 3 students is to be chosen. i. What is the probability that all 3 students are in the same class? [3 marks] ii. What is the probability that 2 of the 3 students are in the same class and the other student is in a different class? [3 marks] (b) In a new casino game, two balls are chosen randomly from an urn...
Develop a matlab script file to calculate the practical single phase transformer parameters. The program should...
Develop a matlab script file to calculate the practical single phase transformer parameters. The program should ask the user to provide the following individually: S_rated V1_rated V2_rated With secondary shorted P1 V1 With primary open P2 I2 The program should calculate Req Xeq Zeq Gc Ym Bm Make sure your code will pronmpt a message like: “Enter the real power at the primary winding when the secondary winding is shorted, P1=). Do the same for all parameters S, V1_rated, V2_rated,...
‘Different organizational implementation tools should be designed in order to facilitate the implementation of different types...
‘Different organizational implementation tools should be designed in order to facilitate the implementation of different types of strategy’. Do you agree with this statement? Why or why not? Please illustrate your answers with the two basic generic business-level strategies.
For each of these classes, there are four types of controls: Preventive (Deterrent) Detective Corrective (Recovery)...
For each of these classes, there are four types of controls: Preventive (Deterrent) Detective Corrective (Recovery) Compensating Please assign the correct Class of Security Control and Type of Control that match with the Security Control Listed below. It might be possible that multiple control classes or Control types could be an answer. It could also be None. Security Control Control Class: A-Administration) T-Technical P Physical) Control Type P – Preventive D – Detective CR –Corrective CM-Compensating Security Awareness Training Firewall...
Use the following Average Return and Standard Deviation numbers for each of the asset classes below...
Use the following Average Return and Standard Deviation numbers for each of the asset classes below to calculate the range of one standard deviation from the mean for each asset class. To provide an example, the range has been calculated for Large Corporate Stocks.                                                       Average      Standard          Asset Class                             Return        Deviation          Range Large Company Stocks            11.9%           20.4%     (8.5)% to 32.2% Small Company Stocks            16.7              32.6        ___________ Long-term Corporate Bonds         6.2                8.3        ___________ Long-term Government...
What should a delinquency prevention program based on GST look like? How would it be designed?...
What should a delinquency prevention program based on GST look like? How would it be designed? Explain thoroughly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT