Program to create three classes and
perform multilevel inheritance among them |

|
/*WAP to create three classes and perform multilevel inheritance among
them
*/
#include <iostream.h>
#include <conio.h>
class student
{
public:
char name[100];
intrno;
void input()
{
cout<<"\nEnter the name of the student
: ";
cin>>name;
cout<<endl<<"\nEnter the roll no
of the student : " ;
cin>>rno;
}
void display()
{
cout<<endl<<"Name of the student
: "<<name;
cout<<endl<<"Roll no :
"<<rno;
}
};
class degree:public student
{
public:
char deg[100];
void getdegree()
{
cout<<endl<<"Enter the degree in
which the student studied : ";
cin>>deg;
}
void display()
{
cout<<endl<<"Degree in which the
student studied : "<<deg;
}
};
class post_deg:public degree
{
public:
char degr[100];
void getpdegree()
{
cout<<endl<<"Enter the post
graduation degree in which the student studies : ";
cin>>degr;
}
void display()
{
cout<<endl<<"Post graduation
Degree in which the student studies : "<<degr;
}
};
void main()
{
post_deg p1;
p1.input();
p1.getdegree();
p1.getpdegree();
p1.student::display();
p1.degree::display();
p1.post_deg::display();
getch();
}
|
Output
|
Enter the name of the student : Samir
Enter the roll no of the student : 13
Enter the degree in which the student studied : BCom
Enter the post graduation degree in which the student studies : MCom
Name of the student : Samir
Roll no : 13
Degree in which the student studied : BCom
Post graduation Degree in which the
student studies : MCom
|