MULTILEVEL INHERITANCE ON C++
Advance programming
THIS PROGRAM IS BASED UPON MULTILEVEL INHERITANCE
SO LETS START FROM THERE.
#include<stdio.h>
#include<conio.h>
class Super1
{
protected:
int sup_b;
public:
super()
{
cout <<“\n In Super 1”;
cout <<“\nEnter b :”; cin >>sup_b;
}
void display()
{
cout <<“\nSuper class membres”;
cout <<“\n sup_b=”<<sup_b;
}
~Super1()
{
cout <<“\nDestroying Super1″;
}
};
class Sub_Level 1 :public Super1
{
protected:
long factorial;
public:
sub_Level()
{
factorial();
}
void factorial();
void display()
{
display();
cout <<\nFactorial of” <<sup_b<<” = ” <<fabtorial;
}
{
cout <<“\nDestroying Level 1”; } }; void Sub_Level ::factorial1() { factorial = 1; int m = sup_b; while(m>0)
{
factorial = factorial *m;
m=m-1;
}
}
class sublevel2:Sub_Level1
{
long doublefact;
long doublenum;
public:
sublevel2()
{
doublefact;
doublenum = sup_b*2;
}
void displayfactorialvalues()
{
display factorial();
cout <<“\nDouble Factorial = ” << doublefact;
cout <<“\nDouble sup_b = “<< doublenum;
}
{
cout << “\nDestroying Level 2” ;
}
};
void main()
{
clrscr();
sub level2 sl2;
sl2 . displayfinalvalues();
}