#include<iostream.h>
#include<conio.h>

class student
{
  public:
  int rno;

  public:
  void get()
  {
    cout<<"\n\nEnter the Roll No:";
    cin>>rno;
  }
};

class test1 : public virtual student
{
  protected:
  float score1;

  public:
  void get1()
  {
    cout<<"\n\n1st test score of "<<rno<<" is :";
    cin>>score1;
  }
};

class test2 : public virtual student
{
  protected:
  float score2;

  public:
  void get2()
  {
    cout<<"\n\n2nd test score of "<<rno<<" is :";
    cin>>score2;
  }
};

class avg : public test1, public test2
{
  public:
  int average;

  public:
  void result()
  {
    average=int((score1+score2)/2);
  }
};

class disp : public avg
{
  public:
  void display()
  {
    cout<<"\n\nThe result of "<<rno<<" is "<<average;
  }
};

int main()
{
  disp k;
  k.get();
  k.get1();
  k.get2();
  k.result();
  k.display();
  return 0;
}

You will know the inheritance concept clearly by this program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.