Program to Illustrate The Concept Of Hierarchical Inheritance:
#include<iostream>
using namespace std;
class Number
{
int num;
public:
void getnum()
{
cout<<"\nEnter any Number ";
cin>>num;
}
int returnum()
{
return num;
}
};
class Square:public Number
{
int sqr;
public:
void square()
{
int num=returnum();
sqr=num*num;
cout<<"Square of "<<num<<" is "<<sqr;
}
};
class Cube:public Number
{
int cube;
public:
void cuube()
{
int num=returnum();
cube=num*num*num;
cout<<"Cube of "<<num<<" is "<<cube;
}
};
main()
{
Square a;
a.getnum();
a.square();
Cube b;
b.getnum();
b.cuube();
}
Also See Multiple Inheritance