Make Your Search Easy ! :) Use me

Friday, February 17, 2017

Hierarchical Inheritance


Program to demonstrate hierarchical Inheritance :-

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


class base

{
   int p,q;
     public:
     void base_get()
      {
         cout<<"Enter Value of P :";
           cin>>p;
           cout<<"Enter Value of Q :";
           cin>>q;
        }
     void base_show()
      {
          cout<<"\nData of Base";
         cout<<"\nP = "<<p;
           cout<<"\nQ = "<<q;
        }

  };
class derived1:public base
{
   int r,s;
     public:
     void derived1_get()
      {
         cout<<"Enter Value of R :";
           cin>>r;
           cout<<"Enter Value of S :";
           cin>>s;
        }
     void derived1_show()
      {
         cout<<"\nData of Derived1";
           cout<<"\nR = "<<r;
           cout<<"\nS = "<<s;
        }
  };

class derived2:public base
{
   int a,b;
     public:
     void derived2_get()
      {
         cout<<"Enter Value of A :";
           cin>>a;
           cout<<"Enter Value of B :";
           cin>>b;
        }
     void derived2_show()
      {
         cout<<"\nData of Derived2";
           cout<<"\nA = "<<a;
           cout<<"\nB = "<<b;
        }
  };

void main()
{
   derived1 d1;
derived2 d2;
   d1.base_get();
   d1.derived1_get();
  d2.base_get();
   d2.derived2_get();
   clrscr();
   d1.base_show();
   d2.base_show();
   d1.derived1_show();
  d2.derived2_show();
   getch();
}

No comments:

Post a Comment