PROGRAM FOR MULTILEVEL INHERITANCE
//program for multilevel inheritance
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void getdata(int rn)
{
rollno=rn;
}
void putdata()
{
cout<<"rollno="<<rollno<<endl;
}
};
class test:public student
{
protected:
float sub1;
float sub2;
public:
void getm(float s1,float s2)
{
sub1=s1;
sub2=s2;
}
void putm()
{
cout<<"marks in sub1:"<<sub1<<endl;
cout<<"marks in sub2:"<<sub2<<endl;
}
};
class result:public test
{
float total;
public:
void display();
};
void result::display()
{
total=sub1+sub2;
putdata();
putm();
cout<<"total:"<<total<<endl;
}
void main()
{
result r;
clrscr();
r.getdata(111);
r.getm(75.0,59.5);
r.display();
getch();
}
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void getdata(int rn)
{
rollno=rn;
}
void putdata()
{
cout<<"rollno="<<rollno<<endl;
}
};
class test:public student
{
protected:
float sub1;
float sub2;
public:
void getm(float s1,float s2)
{
sub1=s1;
sub2=s2;
}
void putm()
{
cout<<"marks in sub1:"<<sub1<<endl;
cout<<"marks in sub2:"<<sub2<<endl;
}
};
class result:public test
{
float total;
public:
void display();
};
void result::display()
{
total=sub1+sub2;
putdata();
putm();
cout<<"total:"<<total<<endl;
}
void main()
{
result r;
clrscr();
r.getdata(111);
r.getm(75.0,59.5);
r.display();
getch();
}

Comments
Post a Comment