Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Multi-level inheritance in OOP
WhatsApp
Barkha Gupta
Jan 24
2016
2.5
k
0
0
* /program to illutrate multilevel inheritance./ *
#include < iostream > using namespace std;
class
student
{
protected
:
int
roll;
public
:
void
getdata(
int
);
void
putdata(
void
);
};
void
student::getdata(
int
a)
{
roll = a;
}
void
student::putdata()
{
cout <<
"\nrollno:"
<< roll;
}
class
test:
public
student
{
protected
:
float
sub1;
float
sub2;
public
:
void
get(
float
,
float
);
void
put(
void
);
};
void
test::get(
float
x,
float
y)
{
sub1 = x;
sub2 = y;
}
void
test::put()
{
cout <<
"\n'c' marks:"
<< sub1;
cout <<
"\n'c++' marks:"
<< sub2;
}
class
result:
public
test
{
float
total;
public
:
void
display(
void
);
};
void
result::display(
void
)
{
total = sub1 + sub2;
putdata();
put();
cout <<
"\ntotal="
<< total;
}
int
main()
{
result stu;
stu.getdata(150);
stu.get(78.0, 65.8);
stu.display();
return
0;
}
Inheritence
C++
OOPS
Up Next
Multi-level inheritance in OOP