In: Computer Science
Write a program that computes a patient's bill for a hospital stay. The different components are:
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.
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