Hybrid Inheritance

 

Hybrid Inheritance: In this inheritance, more than one type of inheritance are involved which maybe multiple,multilevel,hierarchical.

Example 1:  




#include<iostream.h>
#include<conio.h>
 class Person
  {
   protected: char name[100];
              int age;
    public: void setPerson()
      {
        cout<<"Enter name:";
        cin>>name;
        cout<<"Enter age:";
        cin>>age;
        }
        void displayPerson()
        {
         cout<<"Name:"<<name<<endl<<"Age:"<<age<<endl;
          }
           };

    class Student : public Person
       {
        protected: int roll;
        public: void setStudent()
          {
           cout<<"Enter roll of student:";
           cin>>roll;
             }

          void displayStudent()
               {
                cout<<"Roll:"<<roll<<endl;
                 }
                  };

          class Employee:public Person
            {
             protected:char address[100];

             public: void setEmployee()
                {
                  cout<<"Enter the address of employee:";
                  cin>>address;
                   }
                void displayEmployee()
                  {
                   cout<<"Address:"<<address<<endl;
                   }
                    };

             class Permanent: public Person,public Employee
                {
                 protected:int id;
                           int insuranceamount;
                 public:  void setAmount()
                    {
                     cout<<"Enter permanent employee id:";
                     cin>>id;
                     cout<<"Enter insurance amount:";
                     cin>>insuranceamount;
                      }

                     void displayAmount()
                      {
                       cout<<"ID:"<<id<<endl<<"Insurance Amount:"<<insuranceamount<<endl;
                       }
                       };

                 class Temporary:public Person,public Employee
                  {
                  protected: int tempEmpID;
                  public: void setTempEmployee()
                    {
                     cout<<"Enter the id of Temproray employee:";
                     cin>>tempEmpID;
                      }

             void displayTempEmployee()
              {
               cout<<"TempEmp ID:"<<tempEmpID<<endl;
                 }
                 };

                 class Contract:public Person,public Employee,public Temporary
                  {
                   protected: int salary;
                              int contractdate;
                   public:  void inputcontract()
                     {
                      cout<<"Enter the salary:";
                      cin>>salary;
                      cout<<"Enter contract date:";
                      cin>>contractdate;
                       }
                        void displaycontract()
                         {
                          cout<<"Salary:"<<salary<<endl<<"Contract Date:"<<contractdate<<endl;
                           }
                           };

                          class DailyWage:public Person,public Employee,public Temporary
                           {
                            protected: int rate_per_day;
                            public:void inputwage()
                             {
                              cout<<"Enter wage of rate per day:";
                              cin>>rate_per_day;
                               }
                               void displaywage()
                               {
                                cout<<"Rate PEr Day:"<<rate_per_day<<endl;
                                  }
                                 };

               void main()
                {
                Student s;
                cout<<"Detail information of Student:"<<endl;

                s.setPerson();
                s.setStudent();
                cout<<endl;
                s.displayPerson();
                s.displayStudent();
                cout<<endl;

                Employee e;
                cout<<"Detail information of Employee:"<<endl;

                e.setPerson();
                e.setEmployee();
                cout<<endl;
                e.displayPerson();
                e.displayEmployee();
                cout<<endl;

               Permanent p;
               p.setAmount();
               p.displayAmount();
                cout<<endl;

                Temporary t;
                 Contract c;
                DailyWage d;
                t.setTempEmployee();
                c.inputcontract();
                d.inputwage();
                cout<<endl;

                cout<<endl;
                t.displayTempEmployee();
                c.displaycontract();
                d.displaywage();
                getch();
                 }
  


2.  Hybrid Inheritance containing(Multilevel and Hierarchical Inheritance)

   #include<iostream.h>
#include<conio.h>
 class Person
  {
   protected: char name[100];
              int age;
    public: void setPerson()
      {
        cout<<"Enter name:";
        cin>>name;
        cout<<"Enter age:";
        cin>>age;
        }
        void displayPerson()
        {
         cout<<"Name:"<<name<<endl<<"Age:"<<age<<endl;
          }
           };

    class Student : public Person
       {
        protected: int roll;
        public: void setStudent()
          {
           cout<<"Enter roll of student:";
           cin>>roll;
             }

          void displayStudent()
               {
                cout<<"Roll:"<<roll<<endl;
                 }
                  };

          class Employee:public Person
            {
             protected:char address[100];
                        int salary;

             public: void setEmployee()
                {
                  cout<<"Enter the address of employee:";
                  cin>>address;
                  cout<<"Enter salary:";
                  cin>>salary;
                   }
                void displayEmployee()
                  {
                   cout<<"Address:"<<address<<endl<<"Salary:"<<salary<<endl;;
                   }
                    };

             class Examination: public Person,public Student
                {
                 protected:int practicalMarks;
                           int theoryMarks;
                 public:  void setMarks()
                    {
                     cout<<"Enter obtained marks in Practical:";
                     cin>>practicalMarks;
                     cout<<"Enter obtained marks in Theory:";
                     cin>>theoryMarks;
                      }

                     void displayMarks()
                      {
                       cout<<"PracticalMarks:"<<practicalMarks<<endl<<"TheoryMarks:"<<theoryMarks<<endl;
                       }
                        };

                 class Result:public Person,public Student,public Examination
                  {
                  protected: int totalMarks;
                  public: void calculateTotal()
                    {
                     totalMarks=practicalMarks+theoryMarks;
                     cout<<"Total Marks is";
                      }

             void displayTotal()
              {
               cout<<":"<<totalMarks<<endl;
                 }
                 };
               void main()
                {
                Student s;
                cout<<"Detail information of Student:"<<endl;
                s.setPerson();
                s.setStudent();
                cout<<endl;
                s.displayPerson();
                s.displayStudent();
                cout<<endl;

              Result r;
              r.setMarks();
              r.displayMarks();
              cout<<endl;
              r.calculateTotal();
              r.displayTotal();
              cout<<endl;

              Employee e;
                cout<<"Detail information of Employee:"<<endl;
                e.setPerson();
                e.setEmployee();
                cout<<endl;
                e.displayPerson();
                e.displayEmployee();
                cout<<endl;
                getch();
                 }



 

Comments