PROGRAM TO SHOW MULTILEVEL INHERITANCE

by - December 20, 2018

/*WRITE A PROGRAM TO SHOW MULTILEVEL INHERITANCE*/

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void getnumber(int);
void putnumber();
};
void student::getnumber(inta)
{
rollno=a;
}
void student::putnumber()
{
cout<<"Rollno="<<rollno;
}
class test:public student
{
protected:
int sub1;
int sub2;
public:
void getmarks(int,int);
void putmarks();
};
void test::getmarks(intx,inty)
{

sub1=x;
sub2=y;
}
void test::putmarks()
{
cout<<"\nMarks in sub1="<<sub1;
cout<<"\nMarks in sub2="<<sub2;
}
class result:public test
{
protected:
int total;
public:
void display();
};
void result::display()
{
total=sub1+sub2;
putnumber();
putmarks();
cout<<"\nTotal marks="<<total;
}
void main()
{
resultR1;
R1.getmarks(70,90);
R1.getnumber(150);
R1.display();
getch();
}

----------------------------------------------------------
OUTPUT:-

You May Also Like

0 comments