a) 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 <stdio.h>
#include <iostream>
using namespace std;
class MedicalStaff{
string ID;
public:
void getID(string id){
ID = id;
}
void showID(){
cout<<"ID: "<<ID<<endl;
}
};
class Doctor: public MedicalStaff{
protected:
string PMDC;
public:
void getPMDC(string pm){
PMDC = pm;
}
void showPMDC(){
cout<<"PMDC: "<<PMDC<<endl;
}
};
class SkinSpecialist: public Doctor{
string experience;
public:
void getEXP(string expr){
experience = expr;
}
void showEXP(){
cout<<"Experience: "<<experience<<endl;
}
};
int main()
{
// Instantiate using parent class
MedicalStaff medstaff;
medstaff.getID("1");
medstaff.showID();
cout<<endl;
// Instatiating object using sub-classes (Doctor)
Doctor dr;
dr.getPMDC("11212761");
dr.showPMDC();
dr.getID("2");
dr.showID();
cout<<endl;
// Instatiating object using sub-classes (Doctor)
SkinSpecialist sdr;
sdr.getPMDC("6734534");
sdr.showPMDC();
sdr.getID("3");
sdr.showID();
sdr.getEXP("10yrs");
sdr.showEXP();
return 0;
}
Comments
Leave a comment