C++ 11. In this exercise, you will design various classes and write a program to
ID: 664403 • Letter: C
Question
C++
11. 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 member 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.
I have the code done, but would like to have the comments added for the program.
//billType.cpp
#include "billType.h"
billType::billType(int ID, double Med, double pDrF, double room_Charge)
{
PtID = ID;
MedChg = Med;
DrF = pDrF;
RmChg = room_Charge;
}
void billType::setMedChg(double Med)
{
MedChg = Med;
}
double billType::getMedChg() const
{
return MedChg;
}
void billType::setDrF(double pDrF)
{
DrF = pDrF;
}
double billType::getDrF() const
{
return DrF;
}
void billType::setRmChg(double pRmChg)
{
RmChg = pRmChg;
}
double billType::getRmChg() const
{
return RmChg;
}
//billType.h
#ifndef billType_H
#define billType_H
#include <iostream>
#include <string>
using namespace std;
class billType
{
private :
int PtID;
double MedChg;
double DrF;
double RmChg;
public:
billType(int PtID = 0, double MedChg = 0, double DrF = 0, double RmChg = 0);
void setMedChg(double MedChg);
double getMedChg() const;
void setDrF(double DrF);
double getDrF() const;
void setRmChg(double RmChg);
double getRmChg() const;
};
#endif billType_H
//dateType.cpp
#include <iostream>
#include "dateType.h"
using namespace std;
void dateType::setDate(int Month, int Day, int Year)
{
nMnth = Month;
nDay = Day;
nYr = Year;
}
int dateType::getDay() const
{
return nDay;
}
int dateType::getMonth() const
{
return nMnth;
}
int dateType::getYear() const
{
return nYr;
}
void dateType::printDate() const
{
cout << nMnth << "-" << nDay << "-" << nYr;
}
//Constructor with parameters
dateType::dateType(int Month, int Day, int Year)
{
nMnth = Month;
nDay = Day;
nYr = Year;
}
//dateType.h
#ifndef dateType_H
#define dateType_H
class dateType
{
public:
void setDate(int Month, int Day, int Year);
int getDay() const;
int getMonth() const;
int getYear() const;
void printDate() const;
dateType(int Month = 1, int Day = 1, int Year = 1900);
private:
int nMnth;
int nDay;
int nYr;
};
#endif
//doctorType.cpp
#include "doctorType.h"
doctorType::doctorType(string First, string Last ,string pDrSpec)
{
setName(First,Last);
Spec = pDrSpec;
}
void doctorType::setSpec(string pDrSpec)
{
Spec = pDrSpec;
}
string doctorType::getSpec()
{
return Spec;
}
//doctorType.h
#ifndef doctorType_H
#define doctorType_H
#include<iostream>
#include<string>
#include "personType.h"
using namespace std;
//inherits from personType class
class doctorType : public personType
{
private :
string Spec;
public:
//public member function of doctor class
doctorType(string First = "", string Last = "", string Spec = "");
void setSpec(string Spec) ;
string getSpec() ;
};
#endif doctorType_H
//main.cpp
#include<iostream>
//Include header files
#include "doctorType.h"
#include "patientType.h"
#include "dateType.h"
#include "billType.h"
using namespace std;
int main()
{
//create an object of class
doctorType doctor("Bob", "Evans", "Endocrinologist");
cout << "**********************************" << endl;
cout << "** Doctor Details **" << endl;
cout << "**********************************" << endl;
cout << "** Dr. Name: " << doctor.getfName() << " " << doctor.getlName() << endl;
cout << "** Specialty: " << doctor.getSpec() << endl;
cout << "**********************************" << endl;
cout << endl;
//Create three dateType objects for date of birth,
//admit date and dicahrage date
dateType dtBth(10,12,1954);
dateType admtDt(6,25,2015);
dateType DcDt(7,1,2015);
patientType patient("Don","Johnson", 12345, 60, dtBth, admtDt, DcDt, doctor);
cout << "**********************************" << endl;
cout << "** Patient Details **" << endl;
cout << "**********************************" << endl;
cout << "** Patient Name: " << patient.getfName() << " " << patient.getlName() << endl;
cout << "** Patient ID: " << patient.getPtID() << endl;
cout << "** Age: " << patient.getAge() << endl;
cout << "** Date Of Birth: ";
patient.getDoB().printDate();
cout << endl;
cout << "**********************************" << endl;
cout << endl;
cout << "**********************************" << endl;
cout << "** Visit Details **" << endl;
cout << "**********************************" << endl;
cout << "** Date of Admission: ";
patient.getAdmtDt().printDate();
cout << " ** Date of Discharge: ";
patient.getDcDt().printDate();
cout << " ** Doctor Name: "<< patient.getPcNm() << endl;
cout << "**********************************" << endl;
cout << endl;
//create an instance of billType
billType patientBill(10345,14900,1400,400);
cout << "**********************************" << endl;
cout << "** Billing Details **" << endl;
cout << "**********************************" << endl;
cout << "** Medicine Cost: " << patientBill.getMedChg() << endl;
cout << "** Doctor Fee: " << patientBill.getDrF() << endl;
cout << "** Room Charges: " << patientBill.getRmChg() << endl;
cout << "** Total pay: " << patientBill.getMedChg() + patientBill.getDrF() + patientBill.getRmChg() << endl;
cout << "**********************************" << endl;
system("pause");
return 0;
}
//patientType.cpp
#include <iostream>
#include "patientType.h"
patientType::patientType(string First, string Last, int ID, int PtAge, dateType DoB, dateType pAdmtDt, dateType pDcDt, doctorType pDr)
{
setName(First,Last);
PtID = ID;
Age = PtAge;
dtBth = DoB;
admtDt = pAdmtDt;
DcDt = pDcDt;
Dr = pDr;
}
void patientType::setPtID(int ID)
{
PtID = ID;
}
void patientType::setAge(int pAge)
{
Age = pAge;
}
void patientType::setDoB(dateType DoB)
{
dtBth = DoB;
}
void patientType::setAdmtDt(dateType pAdmtDt)
{
admtDt = pAdmtDt;
}
void patientType::setDcDt(dateType pDcDt)
{
DcDt = pDcDt;
}
void patientType::setPcNm(doctorType pDr)
{
Dr = pDr;
}
int patientType::getPtID()
{
return PtID;
}
int patientType::getAge()
{
return Age;
}
dateType patientType::getDoB()
{
return dtBth;
}
dateType patientType::getAdmtDt()
{
return admtDt;
}
dateType patientType::getDcDt()
{
return DcDt;
}
string patientType::getPcNm()
{
return Dr.getfName().append(" " + Dr.getlName());
}
//patientType.h
#ifndef patientType_H
#define patientType_H
#include<iostream>
#include<string>
#include "personType.h"
#include "dateType.h"
#include "doctorType.h"
using namespace std;
class patientType :public personType
{
private:
int PtID;
int Age;
dateType dtBth;
dateType admtDt;
dateType DcDt;
doctorType Dr;
public:
patientType(string First, string Last, int PtID, int Age, dateType dtBth, dateType admtDt, dateType DcDt, doctorType Dr);
void setPtID(int ID);
int getPtID();
void setAge(int Age);
int getAge();
void setDoB(dateType DoB);
dateType getDoB();
void setAdmtDt(dateType AdmtDt);
dateType getAdmtDt();
void setDcDt(dateType DcDt);
dateType getDcDt();
void setPcNm(doctorType Dr);
string getPcNm();
};
#endif patientType_H
//personType.cpp
#include <iostream>
#include <string>
#include "personType.h"
using namespace std;
void personType::print() const
{
cout << fName << " " << lName;
}
void personType::setName(string First, string Last)
{
fName = First;
lName = Last;
}
string personType::getfName() const
{
return fName;
}
string personType::getlName() const
{
return lName;
}
personType::personType(string First, string Last)
{
fName = First;
lName = Last;
}
//personType.h
#ifndef personType_H
#define personType_H
#include <string>
using namespace std;
class personType
{
public:
void print() const;
void setName(string First, string Last);
string getfName() const;
string getlName() const;
personType(string First = "", string Last = "");
protected:
string fName;
string lName;
};
#endif personType_H
Explanation / Answer
Beow is the program with added line by line comments:-
//billType.cpp
#include "billType.h" //header file fo the class billType
/*parameterized constructor for billType*/
billType::billType(int ID, double Med, double pDrF, double room_Charge)
{
PtID = ID; //initialize patient id
MedChg = Med; //initialize medicine charge
DrF = pDrF; //initialize doctor's fee
RmChg = room_Charge; //initialize room charge
}
void billType::setMedChg(double Med)
{
MedChg = Med; //set the medicine charge
}
double billType::getMedChg() const
{
return MedChg; //get the medicine charge
}
void billType::setDrF(double pDrF)
{
DrF = pDrF; //set the doctor's fee
}
double billType::getDrF() const
{
return DrF; //get the doctor's fee
}
void billType::setRmChg(double pRmChg)
{
RmChg = pRmChg; //set the room charge
}
double billType::getRmChg() const
{
return RmChg; //get the room charge
}
//billType.h
#ifndef billType_H
#define billType_H
#include <iostream>
#include <string>
using namespace std;
class billType
{
private :
int PtID; //varaiable to hold the patient id
double MedChg; //varaiable to hold the medicine charge
double DrF; //variable to hold the doctor's fee
double RmChg; //variable to hold the room charge
public:
billType(int PtID = 0, double MedChg = 0, double DrF = 0, double RmChg = 0); //declare parameterzied constructor
void setMedChg(double MedChg); //setter method for medicine charge
double getMedChg() const; //getter method for medicine charge
void setDrF(double DrF); //setter method for doctor's fee
double getDrF() const; //getter method for doctor's fee
void setRmChg(double RmChg); //setter method for room charge
double getRmChg() const; //getter method for room charge
};
#endif billType_H
//dateType.cpp
#include <iostream>
#include "dateType.h" //header file containing declaration of dateType object
using namespace std;
void dateType::setDate(int Month, int Day, int Year) //method to set the date
{
nMnth = Month;
nDay = Day;
nYr = Year;
}
int dateType::getDay() const
{
return nDay; //return the day from the date
}
int dateType::getMonth() const
{
return nMnth; //return the month from the date
}
int dateType::getYear() const
{
return nYr; //return the year from the date
}
void dateType::printDate() const
{
cout << nMnth << "-" << nDay << "-" << nYr; //print the date
}
//Constructor with parameters
dateType::dateType(int Month, int Day, int Year)
{
nMnth = Month; //set month
nDay = Day; //set day
nYr = Year; //set year
}
//dateType.h
#ifndef dateType_H
#define dateType_H
class dateType
{
public:
void setDate(int Month, int Day, int Year); //setter method to set the date
int getDay() const; //method to get the day
int getMonth() const; //method to get the month
int getYear() const; //method to get the year
void printDate() const; //method to print the date
dateType(int Month = 1, int Day = 1, int Year = 1900); //parameterized constructor to set the date
private:
int nMnth; //variable to hold the month
int nDay; //variable to hold the day
int nYr; //variable to hold the year
};
#endif
//doctorType.cpp
#include "doctorType.h" //header file containing the declaration of doctorType object
/*parameterized constructor for doctorType*/
doctorType::doctorType(string First, string Last ,string pDrSpec)
{
setName(First,Last); //set the doctor's first and last name
Spec = pDrSpec; //set the doctor's specialization
}
void doctorType::setSpec(string pDrSpec)
{
Spec = pDrSpec; //set the doctor's specialization
}
string doctorType::getSpec()
{
return Spec; //get the doctor's specialization
}
//doctorType.h
#ifndef doctorType_H
#define doctorType_H
#include<iostream>
#include<string>
#include "personType.h" //header file containing the declaration of personType object
using namespace std;
//inherits from personType class
class doctorType : public personType
{
private :
string Spec; //variable to hold the specialization
public:
//public member function of doctor class
doctorType(string First = "", string Last = "", string Spec = ""); //parameterized constructor
void setSpec(string Spec) ; //method to set the speialization
string getSpec() ; //method to get the specialization
};
#endif doctorType_H
//main.cpp
#include<iostream>
//Include header files
#include "doctorType.h"
#include "patientType.h"
#include "dateType.h"
#include "billType.h"
using namespace std;
int main()
{
//create an object of class doctorType
doctorType doctor("Bob", "Evans", "Endocrinologist");
cout << "**********************************" << endl;
cout << "** Doctor Details **" << endl;
cout << "**********************************" << endl;
cout << "** Dr. Name: " << doctor.getfName() << " " << doctor.getlName() << endl; //display doctor's first and last name
cout << "** Specialty: " << doctor.getSpec() << endl; //display doctor's specialization
cout << "**********************************" << endl;
cout << endl;
//Create three dateType objects for date of birth,
//admit date and dicahrage date
dateType dtBth(10,12,1954);
dateType admtDt(6,25,2015);
dateType DcDt(7,1,2015);
/*craete an object of class patientType*/
patientType patient("Don","Johnson", 12345, 60, dtBth, admtDt, DcDt, doctor);
cout << "**********************************" << endl;
cout << "** Patient Details **" << endl;
cout << "**********************************" << endl;
cout << "** Patient Name: " << patient.getfName() << " " << patient.getlName() << endl;//display patient's first and last anme
cout << "** Patient ID: " << patient.getPtID() << endl; //display patient id
cout << "** Age: " << patient.getAge() << endl; //display patient's age
cout << "** Date Of Birth: ";
patient.getDoB().printDate(); //display patient's date of birth
cout << endl;
cout << "**********************************" << endl;
cout << endl;
cout << "**********************************" << endl;
cout << "** Visit Details **" << endl;
cout << "**********************************" << endl;
cout << "** Date of Admission: ";
patient.getAdmtDt().printDate(); //display patient's admission date
cout << " ** Date of Discharge: ";
patient.getDcDt().printDate(); //display patient's discharge date
cout << " ** Doctor Name: "<< patient.getPcNm() << endl; //display patient's doctor name
cout << "**********************************" << endl;
cout << endl;
//create an instance of billType
billType patientBill(10345,14900,1400,400);
cout << "**********************************" << endl;
cout << "** Billing Details **" << endl;
cout << "**********************************" << endl;
//display patient's medicine cost
cout << "** Medicine Cost: " << patientBill.getMedChg() << endl;
cout << "** Doctor Fee: " << patientBill.getDrF() << endl; //dislay doctor's fee
cout << "** Room Charges: " << patientBill.getRmChg() << endl; //display room charges
cout << "** Total pay: " << patientBill.getMedChg() + patientBill.getDrF() + patientBill.getRmChg() << endl; //display total payment to be made by the patient
cout << "**********************************" << endl;
system("pause");
return 0;
}
//patientType.cpp
#include <iostream>
#include "patientType.h"
/*parameterized constructor for object patientType*/
patientType::patientType(string First, string Last, int ID, int PtAge, dateType DoB, dateType pAdmtDt, dateType pDcDt, doctorType pDr)
{
setName(First,Last); //set patient's first and last name
PtID = ID; //set patient id
Age = PtAge; //set patient age
dtBth = DoB; //set patient date of birth
admtDt = pAdmtDt; //set patient admission date
DcDt = pDcDt; //set patient's discharge date
Dr = pDr; //set patient's doctor
}
void patientType::setPtID(int ID)
{
PtID = ID; //set patientd id
}
void patientType::setAge(int pAge)
{
Age = pAge; //set patient age
}
void patientType::setDoB(dateType DoB)
{
dtBth = DoB; //set patient date of birth
}
void patientType::setAdmtDt(dateType pAdmtDt)
{
admtDt = pAdmtDt; //set patient admission date
}
void patientType::setDcDt(dateType pDcDt)
{
DcDt = pDcDt;//set patient discharge date
}
void patientType::setPcNm(doctorType pDr)
{
Dr = pDr; //set patient's doctors
}
int patientType::getPtID()
{
return PtID; //retun the patient id
}
int patientType::getAge()
{
return Age; //return the patient's age
}
dateType patientType::getDoB()
{
return dtBth; //return patient's date of birth
}
dateType patientType::getAdmtDt()
{
return admtDt; //return patient's admission date
}
dateType patientType::getDcDt()
{
return DcDt; //return patient's discharge date
}
string patientType::getPcNm()
{
return Dr.getfName().append(" " + Dr.getlName());//return the doctor's first and last name
}
//patientType.h
#ifndef patientType_H
#define patientType_H
#include<iostream>
#include<string>
#include "personType.h"
#include "dateType.h"
#include "doctorType.h"
using namespace std;
class patientType :public personType
{
private:
int PtID; //variable to hold patient id
int Age; //variable to hold patient age
dateType dtBth; //variable to hold patient date of birth
dateType admtDt; //varaiable to hold admission date
dateType DcDt; //variable to hold discharge date
doctorType Dr; //variable to hold doctor's name
public:
patientType(string First, string Last, int PtID, int Age, dateType dtBth, dateType admtDt, dateType DcDt, doctorType Dr); //parameterized constructor
void setPtID(int ID); //method to set the patient id
int getPtID(); //method to get the patient id
void setAge(int Age); //method to set patient age
int getAge(); //method to get patient age
void setDoB(dateType DoB); //method to set date of birth
dateType getDoB(); //method to get date of birth
void setAdmtDt(dateType AdmtDt); //method to set admission date
dateType getAdmtDt(); //method to get admission date
void setDcDt(dateType DcDt); //method to set discharge date
dateType getDcDt(); //method to get discharge date
void setPcNm(doctorType Dr); //method to set patient's doctor name
string getPcNm(); //method to get patient's doctor name
};
#endif patientType_H
//personType.cpp
#include <iostream>
#include <string>
#include "personType.h" //header file for personType object
using namespace std;
void personType::print() const
{
cout << fName << " " << lName; //display first and last name
}
void personType::setName(string First, string Last)
{
fName = First; //set first name
lName = Last; //set last name
}
string personType::getfName() const
{
return fName; //return the first name
}
string personType::getlName() const
{
return lName; //return the last name
}
personType::personType(string First, string Last) //parameterized constructor
{
fName = First; //set the first name
lName = Last; //set the last name
}
//personType.h
#ifndef personType_H
#define personType_H
#include <string>
using namespace std;
class personType
{
public:
void print() const; //method to display details
void setName(string First, string Last); //method to set name
string getfName() const; //method to get first name
string getlName() const; //method to get last name
personType(string First = "", string Last = ""); //parameterized constructor
protected:
string fName; //variable to hold first name
string lName; //variable to hold last name
};
#endif personType_H
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.