Program to illustrate multi level inheritance in C++
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Student
{
private:
int rollno;
char name[20];
public:
void getdata(int r,char n[10])
{
rollno=r;
strcpy(name,n);
}
void display()
{
cout<<rollno<<" "<<name<<endl;
}
};
class Test:public Student
{
protected:
float m1,m2;
public:
void getdata(int r,char n[20],float x,float y)
{
Student::getdata(r,n);
m1=x;
m2=y;
}
void display()
{
Student::display();
cout<<m1<<" "<<m2<<endl;
}
};
class Result:public Test
{
private:
float total;
public:
void getdata(int r,char n[20],float x,float y)
{
Test::getdata(r,n,x,y);
}
void display()
{
Test::display();
total=m1+m2;
cout<<total;
}
};
void main()
{
clrscr();
Result R;
R.getdata(1,"Abc",56,67);
R.display();
getch();
}
OUTPUT
1 Abc
56 67
123