// C++ program to implement Multilevel Inheritance
#include <iostream.h>
// single base class
class Student {
public:
int rollno;
void get_rollno(int rn)
{
rollno=rn;
}
void show_rollno()
{
cout<<" Roll Number: "<<rollno<<endl;
}
};
// derived class from base class
class Test : public Student
{
protected:
int s1,s2,s3;
public:
void get_marks(int a, int b, int c)
{
s1=a;
s2=b;
s3=c;
}
void show_marks()
{
cout<<" Marks in subject 1: "<<s1<<endl;
cout<<" Marks in subject 2: "<<s2<<endl;
cout<<" Marks in subject 3: "<<s3<<endl;
}
};
// derived from class derive1
class Result : public Test
{
int total;
public:
// function to print total Marks
void display()
{
total=s1+s2+s3;
show_rollno();
show_marks();
cout << "Total Marks: "<< total<< endl;
}
};
int main()
{
// objects of sub class
Result stud1,stud2;
stud1.get_rollno(415);
stud1.get_marks(65,67,70);
stud1.display();
stud2.get_rollno(425);
stud2.get_marks(55,63,60);
stud2.display();
return 0;
}
0 Comments
Post a Comment