Write a class Medical Staff that contains an attribute ID to store staff’s identity. The class contains member functions to input and display ID. Write a child class Doctor that inherits Medical Class. It additionally contains an attribute to store doctor’s PMDC number. It also contains member functions to input and show the PMDC number. Write another class Skin Specialist that inherit Doctor Class. It additionally contains an attribute to store working experience as specialist. It also contains member functions to input and show the experience. Test these classes from main() by creating objects of derived classes and testing functions in a way that clear concept of multi-level Inheritance.
#include<iostream>
using namespace std;
class MedicalStaff{
private:
//This class has an attribute called id
int id;
public:
int input_staff(){
cin>>this->id;
return id;
}
void show_staff_id(){
cout<<"The id of the medical staff: \t "<<this->id<<endl;
}
};
//The class Doctor is inheriting from the class Medical staff
class Doctor: public MedicalStaff{
private:
int pmdcNumber;
public:
int input_doctor(){
cin>>this->pmdcNumber;
return pmdcNumber;
}
void show_PMDC(){
cout<<"The doctor PMDC number: \t "<<this->pmdcNumber<<endl;
}
};
//This skin specialist class is inheriting from the class Doctor
class SkinSpecialist: public Doctor{
private:
int working_experience;
public:
int specialist_input(){
cin>>this->working_experience;
return working_experience;
}
void specialist_show(){
cout<<"The working experience is: \t "<<this->working_experience<<endl;
}
};
int main(){
//Multilevel inheritance demostrated by creating an object of SKinSpecialist class. Then using the object to
// call the member functions of the class Medical class and class Doctor
SkinSpecialist s;
cout<<"Enter the medical staff id\n"<<endl;
s.input_staff();
cout<<"Enter the doctor's PMDC number"<<endl;
s.input_doctor();
cout<<"Enter the skin specialists' working experience"<<endl;
s.specialist_input();
s.show_staff_id();
s.show_PMDC();
s.specialist_show();
}
Comments
Leave a comment