Write a C++ program to demonstrate Multiple Level inheritance.
Inheritance types
1. Single inheritance2. Multi Level inheritance
3. Multiple Level inheritance
4. Hybrid inheritance
3. Multiple Level inheritance :-
Code :-
/**********program to implement inheritance (Multiple Level inheritance)*****/
#include<iostream.h>
#include<conio.h>
class vehical
{
int code;
public:
void get()
{
cout<<"Enter The Vehical Code :- ";
cin>>code;
}
int get_code()
{
return(code);
}
};
class twheeler:public vehical
{
char tname [10];
long int tprice;
public :
void input()
{
cout<<"\nEnter Two Wheeler Name :- ";
cin>>tname;
cout<<"Enter Two Wheeler Price :- ";
cin>>tprice;
}
void output()
{
cout<<"\nTwo Wheeler Name :- "<<tname;
cout<<"\nTwo Wheeler Price :- "<<tprice;
}
};
class fwheeler:public vehical
{
char fname [10];
long int fprice;
public :
void input()
{
cout<<"\nEnter Four Wheeler Name :- ";
cin>>fname;
cout<<"Enter Four Wheeler Price :- ";
cin>>fprice;
}
void output()
{
cout<<"\nFour Wheeler Name :- "<<fname;
cout<<"\nFour Wheeler Price :- "<<fprice;
}
};
void main()
{
clrscr();
twheeler t1;
fwheeler f1;
t1.get();
if(t1.get_code()==1)
{
t1.input();
t1.output();
}
else
{
f1.input();
f1.output();
}
getch();
}
/*
Output :-
Enter The Vehical Code :- 1
Enter Two Wheeler Name :- Shine
Enter Two Wheeler Price :- 67000
Two Wheeler Name :- Shine
Two Wheeler Price :- 67000
*/
Output :-