In this exercise, you will design various classes and write a program to compute
ID: 3664052 • Letter: I
Question
In this exercise, you will design various classes and write a program to computerize the billing system of a hospital.
a. Design the class doctorType, inherited from the class personType, defined in Chapter 10, with an additional data member to store a doctor’s speciality. Add appropriate constructors and mem- ber functions to initialize, access, and manipulate the data members.
b. Design the class billType with data members to store a patient’s ID and a patient’s hospital charges, such as pharmacy charges for medicine, doctor’s fee, and room charges. Add appropriate constructors and member functions to initialize, access, and manipulate the data members.
c. Design the class patientType, inherited from the class personType, defined in Chapter 10, with additional data members to store a patient’s ID, age, date of birth, attending physician’s name, the date when the patient was admitted in the hospital, and the date when the patient was discharged from the hospital. (Use the class dateType to store the date of birth, admit date, discharge date, and the class doctorType to store the attending physician’s name.) Add appropriate constructors and member functions to initialize, access, and manipulate the data members. Write a program to test your classes.
d. Explain each part of the code and what it is doing and how the information is passed between classes
Found in C++ Programming: From Problem Analysis to Program Design, 6e page 780
Plase pay close attentition to the class requirements.
Explanation / Answer
// personType.cpp
#include <string>
using namespace std;
class personType
{
public:
void print() const;
//Function to output the first name and last name
//in the form firstName lastName.
void setName(string first, string last);
//Function to set firstName and lastName according
//to the parameters.
//Postcondition: firstName = first; lastName = last;
string getFirstName() const;
//Function to return the first name.
//Postcondition: The value of firstName is returned.
string getLastName() const;
//Function to return the last name.
//Postcondition: The value of lastName is returned.
personType(string first = "", string last = "");
//Constructor
//Sets firstName and lastName according to the parameters.
//The default values of the parameters are null strings.
//Postcondition: firstName = first; lastName = last;
private:
string firstName; //variable to store the first name
string lastName; //variable to store the last name
};
void personType::print() const
{
cout << firstName << " " << lastName;
}
void personType::setName(string first, string last)
{
firstName = first;
lastName = last;
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getLastName() const
{
return lastName;
}
//constructor
personType::personType(string first, string last)
{
firstName = first;
lastName = last;
}
/*----------------------------------------------------------------*/
//doctorType.cpp
#include "personType.cpp"
class doctorType : public personType
{
string speciality;
public:
doctorType(string first, string last, string special)
{
super(first,last);
speciality=special;
}
string getSpeciality() const
{
return speciality;
}
void setSpeciality(string special)
{
speciality=special;
}
void print() const
{
cout << firstName << " " << lastName" " << speciality;
}
};
/*----------------------------------------------------------------*/
//billType.cpp
class billType
{
/*data members to store a patient’s ID and a patient’s hospital charges
pharmacy charges for medicine, doctor’s fee, and room charges */
int patientID;
float pharmacyCharge;
float doctorFee;
float roomCharge;
/*constructors*/
public:
billType(int ID, float pharmaCharge,float drFee,float roomFee)
{
patientID=ID;
pharmacyCharge=pharmaCharge;
doctorFee=drFee;
roomCharge=roomFee;
}
/* Add appropriate and member functions to initialize, access, and manipulate the data members.*/
void setPatientID(int ID)
{
patientID=ID;
}
void setPharmacyCharge(float pharmaCharge)
{
pharmacyCharge=pharmaCharge;
}
void setDoctorFee(float drFee)
{
doctorFee=drFee;
}
void getRoomCharge(float roomFee)
{
roomCharge=roomFee;
}
int getPatientID()
{
return patientID;
}
float getPharmacyCharge()
{
return pharmacyCharge;
}
float getDoctorFee()
{
return doctorFee;
}
float getRoomCharge()
{
return roomCharge;
}
};
/*----------------------------------------------------------------*/
//patientType.cpp
#include "personType.cpp"
#include "dateType.cpp"
#include "doctorType.cpp"
class patientType : public personType
{
/*data members to store a patient’s ID, age, date of birth, attending physician’s name,
the date when the patient was admitted in the hospital,
and the date when the patient was discharged from the hospital.*/
int patientID;
int age;
dateType DOB;
doctorType physicianName;
dateType admittedDate;
dateType dischargedDate;
public:
patientType(){}
patientType(int ID,int a,dateType dob,string drname,dateType admitted,dateType discharged)
{
DOB.setDate(dob.getDay(),dob.getMonth(),dob.getYear());
physicianName.setName(drname);
admitted.setDate(admitted.getDay(),admitted.getMonth(),admitted.getYear());
dischargedDate.setDate(discharged.getDay(),discharged.getMonth(),discharged.getYear());
patientID=ID;
age=a;
}
};
/*----------------------------------------------------------------*/
//dateType.cpp
class dateType
{
public:
void setDate(int month, int day, int year);
//Function to set the date.
//The member variables dMonth, dDay, and dYear are set
//according to the parameters.
//Postcondition: dMonth = month; dDay = day;
// dYear = year
int getDay() const;
//Function to return the day.
//Postcondition: The value of dDay is returned.
int getMonth() const;
//Function to return the month.
//Postcondition: The value of dMonth is returned.
int getYear() const;
//Function to return the year.
//Postcondition: The value of dYear is returned.
void printDate() const;
//Function to output the date in the form mm-dd-yyyy.
dateType(int month = 1, int day = 1, int year = 1900);
//Constructor to set the date
//The member variables dMonth, dDay, and dYear are set
//according to the parameters.
//Postcondition: dMonth = month; dDay = day; dYear = year;
// If no values are specified, the default
// values are used to initialize the member
// variables.
private:
int dMonth; //variable to store the month
int dDay; //variable to store the day
int dYear; //variable to store the year
};
void dateType::setDate(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getYear() const
{
return dYear;
}
void dateType::printDate() const
{
cout << dMonth << "-" << dDay << "-" << dYear;
}
//Constructor with parameters
dateType::dateType(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}
/*----------------------------------------------------------------*/
#include <iostream>
#include "patientType.cpp"
#include "billType.cpp";
using namespace std;
int main()
{
dateType DOB(10,10,2000);
dateType admitted(1,12,2015);
dateType discharged(12,1,2016);
patientType P(12,25,DOB,"JAMES",admitted,discharged);
billType b(12,500.75,500,1200.50);
cout<<endl<<"==============================";
cout<<endl<<"BILL";
cout<<endl<<"==============================";
cout<<endl<<"Patient ID:"<<b.getPatientID();
cout<<endl<<"Doctor Fees:"<<b.getDoctorFee();
cout<<endl<<"Pharmacy Charge:"<<b.getPharmacyCharge();
cout<<endl<<"Room Charge:"<<b.getRoomCharge();
cout<<endl<<"==============================";
cout<<endl<<"Total fees:"<<(b.getDoctorFee()+b.getPharmacyCharge()+b.getRoomCharge());
cout<<endl<<"==============================";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.