C PROGRAMMING CODE NEEDED IS BELOW Question Inheritance Deri
C++ PROGRAMMING
CODE NEEDED IS BELOW:
Question (Inheritance) Derive the class doctor Type, 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. doctor Type(string, string, string),llFirstname Lastname Specialty doctor Type0,/Default constructor void set Specialty(string);llSet doctor specialty string getSpecialty0const ll Get doctor specialty void printoconst;/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 (all are integers). Then, implement following class member function prototypes. patient Type string, string, int, int, int illFirstname Lastname id age dob patient Type0, Default constructor void setld(int);llSet patient id void setage(int);llSet patient age void set Dob(int), MISet patient DOB int getld0constilGet patient id int getage0constilGet patient int get Doboconst,//Get patient DOB void printoconst, /Display patient information the same as given output formatSolution
#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: personType
{
private:
string speciality;
public:
doctorType(string firstname,string lastname,string speciality):personType(firstname,lastname)
{
this->speciality = speciality;
}
doctorType()
{
speciality = \" \";
}
void setSpeciality(string speciality)
{
this->speciality = speciality;
}
string getSpeciality()const
{
return speciality;
}
void print() const
{
personType::print();
cout << \" Speciality = \"<<speciality<< endl;
}
};
class patientType: personType
{
private:
int id;
int age;
int dob;
public:
patientType(string firstname,string lastname,int id,int age,int dob):personType(firstname,lastname)
{
this->id = id;
this->age = age;
this->dob = dob;
}
patientType()
{
id = 0;
age = 0;
dob = 0;
}
void setId(int id)
{
this->id = id;
}
void setage(int age)
{
this->age = age;
}
void setDob(int dob)
{
this->dob = dob;
}
int getId()const
{
return id;
}
int getage()const
{
return age;
}
int getDob()const
{
return dob;
}
void print() const
{
personType::print();
cout << \"ID = \"<<id<<\" Age = \"<<age<<\" Date of Birth = \"<<dob<< endl;
}
};
class billType: personType
{
private:
doctorType doctor;
patientType patient;
double charges;
public:
billType(doctorType doctor,patientType patient)
{
this->patient = patient;
this->doctor= doctor;
}
void setCharge(double charges)
{
this->charges = charges;
}
double getCharge()const
{
return charges;
}
void print()const
{
cout<<\"Charges = \"<<charges;
}
};
//--------------------driver program
int main()
{
personType person1(\"Lisa\", \"Regan\");
doctorType doctor1(\"Sarah\", \"Conner\", \"Dentist\");
patientType patient1(\"Sam\", \"Fire\",200,100,1916);
billType b1(doctor1,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;
}
output:



