Hybrid Inheritance


The combination of more than one inheritance is known as hybrid inheritance.

Hybrid Inheritance
     

#include <iostream.h>
class student
{
      int r_no;
      char name[20];
      public:
      void instudent()
      {
            cout<<”Enter Roll Number:”;
            cin>>r_no;
            cout<<”Enter Name:”;
            cin>>name;
      }
      void outstudent()
      {
            cout<<”Roll Number:”<<r_no<<endl;
            cout<<”Name:”<<name<<endl;
      }
};
class TW: virtual public Student
{
      int tmark;
      public:
      void intmark()
      {
            cout<<”Enter Term work mark:”;
            cin>>tmark;
      }
      void outtmark()
      {
            cout<<”Term Work Mark:”<<tmark;
      }
};
class EXT: virtual public Student
{
      int emark;
      public:
      void inemark()
      {
            cout<<”Enter External mark:”;
            cin>>emark;
      }
      void outemark()
      {
            cout<<”External Mark:”<<emark;
      }
};
class Result: public TW, public EXT
{
      int total;
      public:
      void displayResult ()
      {
            total = tmark + emark;
            outstudent ();
            outtmark();
            outemark ();
            cout<<”Total=”<<total;
      }
}
int main ()
{
      Result R[60];
      int i;
      for (i=0;i<60;i++)
      {
            R[i].instudent ();
            R[i].intmark ();
            R[i].inemark();
      }
      for (i=0;i<60;i++)
      {
            R[i].display ();
      }
      return 0;
}

Download Projects


Download Programs