Could someone please answer this C question Implement a base

Could someone please answer this C++ question?

Implement a base class Person. Derive classes Patient and Doctor from Person. A person has a firstName, lastName, and email. Patient has additional data members patientID and condition. Doctor has additional data member specialization.

Write the class definitions, the constructors, and the member functions for all classes. Write a program that tests your Patient and Doctor classes. Your code should be thoroughly commented so that all lines of code have a comment that explains it.

Solution

Answer :-

// Base Class
class Person
{
public :
Student( )
{
cout << \"Default constructor of Base class - Person \" << endl;
}
public :
string firstName;
string lastName;
string email;
};

// Derived Class
class Patient : public Person
{
public:
Patient()
{
cout << \"Default constructor of Derived class - Patient \" << endl;
}
public:
int patientID;
string condition;
};

// Derived Class
class Doctor : public Person
{
public:
Student()
{
cout << \"Default constructor of Derived class - Doctor \" << endl;
}
public:
string specialization;
};

int main()
{
Patient p;
// A Derived class object p can access the non-private members of Base class.
cout << p.patientID;
cout << p.condition;

Doctor d;
// A Derived class object d can access all the non-private members of Base class.
cout << d.specialization;
}

Could someone please answer this C++ question? Implement a base class Person. Derive classes Patient and Doctor from Person. A person has a firstName, lastName,
Could someone please answer this C++ question? Implement a base class Person. Derive classes Patient and Doctor from Person. A person has a firstName, lastName,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site