Write a c program to implement hybrid inheritence

#include<iostream>

using namespace std;

     class student

     {

      protected:

      int roll_no;

      public:

      void get_no(int x);

      void put_no();

     };

     void student::get_no(int x)

     {

      roll_no=x;

   cout<<“the roll is\n”<<roll_no<<“\n”;

     }

 void student::put_no()

     {

      cout<<“the roll is\n”<<roll_no<<“\n”;

     }

     class test:public student

     {

      protected:

      float marks1,marks2;

      public:

void get_marks(float a,float b);

void put_marks();

      };

  void test::get_marks(float a,float b)

  {

  marks1=a;

  marks2=b;

  }

  void test::put_marks()

  {

  cout<<“the marks of the students are\n”<<marks1<<marks2<<“\n”;

  }

  class sports

  {

  protected:

  float score;                                                                                                                                                                

  public:

  void get_score(float s);

  void put_score();

  };

  void sports::get_score(float s)

  {

  score=s;

  }

  void sports::put_score()

  {

  cout<<“the score of the student is\n”<<score<<“\n”;

  }

  class result:public test,public sports

  {

  public:

  float total;

  void display();

  };

  void result::display()

  {

  total=marks1+marks2+score;

  cout<<“the total of the student is\n”<<total<<“\n”;

  }

  int main()

  {

  result r;

  r.get_no(2);

  r.get_marks(60.6,80.5);

  r.get_score(55.4);

  r.put_no();

  r.put_marks();

  r.put_score();

  r.display();

  return(0);

  }

Output:

The roll is

2

The marks of the students are

60.6 80.5

The score of the student is

55.4

The total of the student is

196.5

Leave a Comment

Your email address will not be published.