Objectives Learn about inheritance Explore how to redefine t

Objectives:

Learn about inheritance

Explore how to redefine the member functions of a base class

Learn about composition/aggregation

Download Lab10.cpp. In this file, the definition of the class personType has given.

Think of the personType as the base class.

Question1. (Inheritance)

Derive the class doctorType, inherited from the class personType, with an additional class member variable member to store a doctor’s specialty(string type) Then, implement following class member function prototypes.

            doctorType(string,string,string);//Firstname Lastname Specialty

            doctorType();//Default constructor

            void setSpecialty(string);//Set doctor specialty

            string getSpecialty()const;// Get doctor specialty

            void print()const;//Display doctor information the same as given output format

Derive the class patientType, inherited from the class personType, with additional class member variables to store a patient’s id, age, and dob (Date of birth)(All are integer). Then, implement following class member function prototypes.

            patientType(string, string, int, int, int);//Firstname Lastname id age dob

            patientType();Default constructor

            void setId(int);//Set patient id

            void setage(int);//Set patient age

            void setDob(int);//Set patient DOB

            int getId()const;//Get patient id

            int getage()const;//Get patient

            int getDob()const;//Get patient DOB

            void print()const; //Display patient information the same as given output format

Question2. (Composition)

Design a class billType, with class member variables to store a patient’s information (patientType), the patient’s doctor’s information (doctorType), and the hospital charges(double). Then, implement following class member function prototypes.

                  billType(doctorType &d, patientType &p); // Constructor

                  void setCharge(double);//Set hospital charges

                  double getCharge()const;//Get hospital charges

            void print()const;//Display a bill information the same as given output format

Use the provided driver program to test your program. You should get the same output.

Submit a single cpp file.

Output:

CAWINDOWSesystem321cmd. kpersonType Prin Person FirstName-Lisa LastName-Regan Kdoctor Type Printing Doctor FirstName Sarah L Conner Specialty Dentist

Solution

#include <iostream>
#include <string>
using namespace std;
// Base class personType
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);

string getFirstName()const;
string getLastName()const;
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 << \"Person FirstName=\"<<firstName << \" LastName=\" << lastName<< endl;
}

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;
}
// --------------------Start your code from here

class doctorType: public personType
{
private:
string specialty;

public:
doctorType(string,string,string);//Firstname Lastname Specialty
doctorType();//Default constructor
void setSpecialty(string);//Set doctor specialty
string getSpecialty()const;// Get doctor specialty
void print()const;//Display doctor information the same as given output format
};

doctorType::doctorType(string f, string l, string s):personType(f,l)
{
specialty=s;
}

doctorType::doctorType():personType(\"\",\"\")
{
specialty=\"\";
}


void doctorType::setSpecialty(string s)
{
specialty=s;
}

string doctorType::getSpecialty()const
{
return specialty;
}

void doctorType::print()const
{
cout << \"Doctor FirstName=\"<<getFirstName() << \" LastName=\" << getLastName()<< \" Speciality=\" << specialty<< endl;
}


class patientType: public personType
{
private:
int id;
int age;
int dob;

public:
patientType(string, string, int, int, int);//Firstname Lastname id age dob
patientType();
void setId(int);//Set patient id
void setage(int);//Set patient age
void setDob(int);//Set patient DOB
int getId()const;//Get patient id
int getage()const;//Get patient
int getDob()const;//Get patient DOB
void print()const; //Display patient information the same as given output format
};

patientType::patientType(string f, string l, int i, int a, int d):personType(f,l)
{
id = i;
age = a;
dob = d;
}

patientType::patientType():personType(\"\",\"\")
{
id = 0;
age = 0;
dob = 0;
}

void patientType::setId(int i)
{
id = i;
}

void patientType::setage(int a)
{
age = a;
}

void patientType::setDob(int d)
{
dob = d;
}

int patientType::getId() const
{
return id;
}

int patientType::getage() const
{
return age;
}

int patientType::getDob() const
{
return dob;
}


void patientType::print() const
{
cout << \"Patient FirstName=\"<<getFirstName() << \" LastName=\" << getLastName()<< \" Id=\" << id << \" Age=\" << age << \" DOB=\" << dob << endl;
}

class billType
{
private:
doctorType doctor;
patientType patient;
double charge;
public:
billType(doctorType &d, patientType &p); // Constructor
billType();
void setDoctor(doctorType);
void setPatient(patientType);
void setCharge(double);//Set hospital charges
double getCharge()const;//Get hospital charges
void print()const;//Display a bill information the same as given output format
};


billType::billType()
{
}

billType::billType(doctorType &d, patientType &p)
{
doctor = d;
patient = p;
}

void billType::setDoctor(doctorType d)
{
doctor = d;
}

void billType::setPatient(patientType p)
{
patient = p;
}

void billType::setCharge(double c)//Set hospital charges
{
charge = c;
}

double billType::getCharge()const//Get hospital charges
{
return charge;
}

void billType::print()const
{
patient.print();
cout << \"Patient\'s \" ;
doctor.print();
cout << \"Hospital charge=\" << charge <<endl;
}

//--------------------driver program
int main()
{

personType person1(\"Lisa\", \"Regan\");
doctorType doctor1(\"Sarah\", \"Conner\", \"Dentist\");
patientType patient1(\"Sam\", \"Fire\",200,100,1916);
billType b1;
b1.setDoctor(doctor1);
b1.setPatient(patient1);
b1.setCharge(250.66);
cout << \"<personType> Printing...\ \";
person1.print();
cout << endl;
cout << \"<doctorType> Printing...\ \";
doctor1.print();
cout << endl;
cout << \"<patientType> Printing...\ \";
patient1.print();
cout << endl;
cout << \"<billType> Printing...\ \";
b1.print();
cout << endl;
return 0;
}

Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this
Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this
Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this
Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this
Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this
Objectives: Learn about inheritance Explore how to redefine the member functions of a base class Learn about composition/aggregation Download Lab10.cpp. In this

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site