Anonymous School
(Minds of Hacker)
--------------------------------
Identify ‘Inheritance’ shown in following figure. Implement it by using suitable member function.
#include <iostream>using namespace std;class student{public:int roll_no;char name[10];void set_roll(){cout << "Enter the Roll No & Name of Students\n";cin >> roll_no >> name;}void get_roll(){cout << "Roll No = " << roll_no << "\nName = " << name << "\n";}};class test : public student{public:int oop_marks, dsu_marks;void set(){cout << "Enter the marks of OOP & DSU\n";cin >> oop_marks >> dsu_marks;}void get(){cout << "Marks of OOP = " << oop_marks << "\nMarks of DSU = "
<< dsu_marks << "\n";
}};class result : public test{public:int total;void display(){get_roll();get();cout << "Total = " << oop_marks + dsu_marks << "\n";}};int main(){result student;student.set_roll();student.set();student.display();}
Output:
Enter the Roll No & Name of Students
25 xyz
Enter the marks of OOP & DSU
89 80
Roll No = 25
Name = xyz
Marks of OOP = 89
Marks of DSU = 80
Total = 169
*******************Don't Make Learning Hard*****************
Follow us on :-
1) YouTube Channel :- Click Here
2) Blog :- Click Here