Write a program to perform Hybrid Inheritance

/*
    Hybrid Inheritance
*/
#include<iostream>
using namespace std;

class Regular
{
    protected:
    int salary;
};

class Casual
{
    protected:
    int daily_wages;
};

class Typist: public Regular,public Casual
{
   protected:
   int speed,experience;
};

class Teacher
{
   protected:
   char subject[20];
   int experience;


};

class Officer
{
    protected:
    char grade,department[20];

};

class Staff :public Teacher,public Officer,public Typist
{
    int code;
    char name[20];

    public:
            void accept();
            void display();

};

void Staff::accept()
{
    cout<<"\n\n Enter Name and Code";
    cin>>name>>code;

    cout<<"\n\n Officer: ";
    cout<<"\n\n Enter grade and department: ";
    cin>>grade>>department;

    cout<<"\n\n Teacher: ";
    cout<<"\n\n Enter Subject and Year of Experience: ";
    cin>>subject>>Teacher::experience;

    cout<<"\n\n Enter Driving Speed and experience: ";
    cin>>speed>>Typist::experience;

    cout<<"\n\n Enter daily wages and salary:";
    cin>>daily_wages>>salary;
}

void Staff::display()
{
    cout<<"\n\n Name:"<<name<<"\n  Code: "<<code;

    cout<<"\n\n Officer: ";
    cout<<"\n Grade: "<<grade<<"\n Department: "<<department;

    cout<<"\n\n Teacher: ";
    cout<<"\n\n Subject "<<subject<<"\n Year of Experience: "<<Teacher::experience;

    cout<<"\n\n Driving Speed "<<speed<<"\n Experience: "<<Typist::experience;

    cout<<"\n\n Daily wages:"<<daily_wages<<"\n Salary:"<<salary;
}

int main()
{
  Staff S;

  S.accept();
  S.display();

  return 0;
}

Previous
Next Post »