Write a C++ program to find out the student details using multilevel inheritance.




Program Algorithm:
Step 1: Include the header files
Step 2: Declare the base class student.
Step 3: Declare and define the function get_ number ( ) and put_number( ).
Step 4: Declare the derived class test for student
Step 5: Declare and define the function get_ marks ( ) and put_marks( ).
Step 6: Declare the derived class result for test
Step 7: Declare and define the function display ( )
Step 8: Create objects for the derived class.
Step 9: Declare the derived class object, call the functions get_ number ( ), get_ marks ( ), display ( ).




Program Code in C++:
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll;
public:
void get_number(int a)
{
roll = a;
}
void put_number()
{
cout<<"Roll Number: "<<roll<<"\n";
}
};
class test : public student
protected:
float sub1;
float sub2;
public:
void get_marks(float x,float y)
{
sub1 = x;
sub2 = y;
}
void put_marks()
{
cout<<"Marks in Subject 1 = "<<sub1<<"\n";
cout<<"Marks in Subject 2 = "<<sub2<<"\n";
}
};
class result : public test
private:
float total;
public:
void display()
{
total = sub1 + sub2;
put_number();
put_marks();
cout<<"Total = "<<total<<"\n";
}
};
void main()
{
clrscr();
result student;
student.get_number(183);
student.get_marks(90.0,70.5);
student.display();
getch();
}





Program Output:
Roll No: 183
Marks in sub 1: 90
Marks in sub 2: 70.5
Total: 160.5
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: