Write a program to perform HIERARCHICAL INHERITANCE

/*
    HIERARCHICAL INHERITANCE
*/
#include<iostream>
using namespace std;

class Staff
{
  private:
       int code;

  public:
        void accept()
        {
          cout<<"\n\n Enter Code: ";
          cin>>code;
        }

        void display()
        {
           cout<<"\n\n Code: "<<code;
        }

};

class Teacher: public Staff
{
  int subject;

  public:
       void accept()
       {
          Staff::accept();

          cout<<"\n\n Enter number of subject: ";
          cin>>subject;
       }

       void display()
       {
          Staff::display();
          cout<<"\n\n Subject: "<<subject;
       }
};

class Officer: public Staff
{
  char grade;

  public:
       void accept()
       {
          Staff::accept();

          cout<<"\n\n Enter Grade : ";
          cin>>grade;
       }

       void display()
       {
          Staff::display();
          cout<<"\n\n Grade: "<<grade;
       }
};

int main()
{
   Teacher t;
   Officer o;

   cout<<"\n\n Teacher: ";
   t.accept();
   t.display();

   cout<<"\n\n Officer: ";
   o.accept();
   o.display();

   return 0;
}

Previous
Next Post »