PROGRAM FOR HIERARCHIAL INHERITANCE

//program for hierarachial inheritance
#include<iostream.h>
#include<conio.h>
class student
{
  protected:
  int rollno;
  public:
  void getn(int a)
  {
    rollno=a;
  }
  void dis1()
  {
    cout<<rollno<<endl;
  }
};
class test:public student
{
  protected:
  float p1,p2;
  public:
  void getm(float a,float b)
  {
   p1=a;
   p2=b;
  }
  void dis2()
  {
    cout<<p1<<endl<<p2<<endl;
  }
};
class sports
{
protected:
 float score;
public:
 void gets(float s)
 {
   score=s;
 }
 void dis3()
 {
   cout<<score<<endl;
 }
};
class result:public test,public sports
{
  float total;
  public:
  void display()
  {
    total=p1+p2+score;
    dis1();
    dis2();
    dis3();
    cout<<"total="<<total<<endl;
  }
};
void main()
{
  result r;
  clrscr();
  r.getn(12345);
  r.getm(99.60,99.80);
  r.gets(0.6);
  r.display();
  getch();
}

Comments

Popular Posts