0% found this document useful (0 votes)
3 views2 pages

2 Multi Level Inheritance

The document presents a C++ program that demonstrates multi-level inheritance through three classes: 'student', 'test', and 'result'. The 'student' class manages student roll numbers, the 'test' class handles marks for two subjects, and the 'result' class calculates and displays the total marks. The main function creates an instance of the 'result' class, sets the roll number and marks, and displays the results.

Uploaded by

bandleraju05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

2 Multi Level Inheritance

The document presents a C++ program that demonstrates multi-level inheritance through three classes: 'student', 'test', and 'result'. The 'student' class manages student roll numbers, the 'test' class handles marks for two subjects, and the 'result' class calculates and displays the total marks. The main function creates an instance of the 'result' class, sets the roll number and marks, and displays the results.

Uploaded by

bandleraju05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//Program to demonstrate multi-level inheritance

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int);
void put_number();
};
void student::get_number(int a)
{
roll_number=a;
}
void student::put_number()
{
cout<<"Roll Number:"<<roll_number<<"\n";
}
class test:public student
{
protected:
float sub1;
float sub2;
public:
void get_marks(float,float);
void put_marks();
};
void test::get_marks(float x,float y)
{
sub1=x;
sub2=y;
}
void test::put_marks()
{
cout<<"Marks in SUB1="<<sub1<<"\n";
cout<<"Marks in SUB2="<<sub2<<"\n";
}
class result:public test
{
float total;
public:
void display();
};
void result:: display()
{
total=sub1+sub2;
put_number();
put_marks();
cout<<"Total="<<total<<"\n";
}

int main()
{
clrscr();
result student1;
student1.get_number(111);
student1.get_marks(75.0,59.5);
student1.display();
getch();
return 0;
}

You might also like