Program to demonstrate Hybrid Inheritance.



Program:
#include<iostream.h>
#include<conio.h>
class student
{
int r_no;
public:
void get(int a)
{
r_no=a;
}
void put()
{
 cout<<"Rollnumber : "<<r_no<<endl;
 }
 };
 class test : virtual public student
 {
  protected :
  float s1,s2;
  public:
  void getmarks(float x,float y)
  {
   s1=x;
   s2=y;
   }
   void putmarks()
   {
    cout<<" Marks in Academics  "<<endl;
     cout<<" Marks in subject 1 : "<<s1<<endl;
      cout<<" Marks in subject 2 :  "<<s2<<endl;
      }
      };
      class sports :virtual public student
      {
       protected :
       float score;
       public:
       void getscore(float s)
       {
score=s;
}
void putscore()
{
 cout<<"Sports score is : "<<score<<endl;
 }
 };
 class result : public test, public sports
 {
 float total;
 public:
 void display()
 {
  total= ((s1+s2+score)/3);
  put();
  putmarks();
  putscore();
  cout<<"Result : " <<total <<endl;
  }};
  int main()
  {
  clrscr();
   result r;
   r.get(01);
   r.getmarks(89,95);
   r.getscore(100);
   r.display();
   getch();
   return 0;
   }



No comments:

How to crack Aptitude Question In GATE and many Competitive Examination

As you know the aptitude in the competitive examination is quite for more challenging to clear it. But believe me it is the easy stuff t...