Wednesday, 1 April 2015

U5P2

Program to Implement Hybrid Inheritance.
Student class have two derived class named as Test, Sports and both Test, Sports has a derived class named as Result which display all the details.

 #include<iostream.h>  
 #include<conio.h>  
 class student  
 {  
      protected:  
      int roll;  
      public:  
      void get()  
      {    //roll =a;  
           cout<<"Roll Number of Student : ";  
           cin>>roll;  
      }  
 };  
   
 class test : virtual public student  
 {  
      public:  
      int marks;  
      void get2()  
      {  
           cout<<"Enter Total Marks Obtained in Test : ";  
           cin>>marks;  
      }  
 };  
   
 class sports : virtual public student  
 {  
      public:  
      int score;  
      void get3()  
      {  
           cout<<"Enter Total Score obtained in Sports : ";  
           cin>>score;  
      }  
 };  
   
 class result : public test, public sports  
 {  
      public:  
      void show_all()  
      {  
           cout<<endl<<"Roll Number of Student is  : "<<roll;  
           cout<<endl<<"Total Marks Obtained(Test)  : "<<marks;  
           cout<<endl<<"Total Score Obtained(Sports) : "<<score;  
      }  
 };  
   
 void main()  
 {  
      clrscr();  
      result obj;  
      obj.get();  
      obj.get2();  
      obj.get3();  
      obj.show_all();  
      getch();  
 }  
   


Output :

No comments:

Post a Comment