Write a c++ program to illustrate multilevel inheritance.




Program Code:
#include<iostream.h>
#include<conio.h>
class student
{
protected : int rollno;
public : void get_num();
void put_num();
};
void student::get_num()
{

cout<<"\nEnter the roll number:\t";
cin>>rollno;
}
void student::put_num()
{
cout<<"Rollnumber: "<<rollno;
}
class test:public student
{
protected : float sub1,sub2;
public:
void get_marks()
{
cout<<"\nEnter the sub1 marks: ";
cin>>sub1;
cout<<"\nEnter the sub2 marks: ";
cin>>sub2;
}
void put_marks()
{
cout<<"\nSub1="<<sub1;
cout<<"\nSub2="<<sub2;
}
};
class result : public test
{
float total;
public:
void display()
{
total=sub1+sub2;
put_num();
put_marks();
cout<<"\nTotal= "<<total;
}
};
int main()
{
clrscr();
result r;
r.get_num();
r.get_marks();
r.display();
getch();
return 0;
}





The output of the above program is:
Enter the roll number: 11111
Enter the sub1 marks: 67
Enter the sub2 marks: 56
Rollnumber: 11111
Sub1=67
Sub2=56
Total= 123





Thanks
Mukesh Rajput
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: