21CSC201T – Object Oriented Design and Programming
Week - 6 – Tutorial Questions
Inheritance: Single, Multiple, Hierarchical, Multilevel and Hybrid
1. Student-Athlete System:
• Design and implement a C++ program using multiple inheritance to model a
scenario where:
1. A Student has a name and roll number.
2. A SportsPlayer has a sport name and ranking.
3. A SportStudent inherits from both Student and SportsPlayer, combining the
properties of both.
The program should include:
• A base class Student with attributes for name and roll number.
• A base class SportsPlayer with attributes for sport name and ranking.
• A derived class SportStudent that inherits from both Student and
SportsPlayer.
• A function to display details of a SportStudent.
• Demonstration of creating an object of SportStudent and displaying its
details.
2. Shape Area Calculation:
• In a graphics application, different shapes need to be managed efficiently.
Implement this scenario using hierarchical inheritance in C++:
1. Create a base class Shape with:
• Functions to get data (e.g., dimensions).
• A function to print data.
• A pure virtual function to calculate the area.
2. Create derived classes Rectangle and Circle that inherit from Shape:
• Rectangle should store length and width and override the area calculation.
• Circle should store radius and override the area calculation.
3. Demonstrate hierarchical inheritance by:
• Creating objects of Rectangle and Circle.
• Invoking the appropriate functions.
• Displaying the calculated area for each shape.
3. Academic Hierarchy:
• In an academic institution, different roles have hierarchical relationships.
Implement this scenario using multilevel inheritance in C++:
1. Create a base class Person that contains:
• A name attribute.
• A function to set and display the name.
2. Create a derived class Teacher that inherits from Person and includes:
• A subject attribute.
• A function to set and display the subject.
3. Create a further derived class Professor that inherits from Teacher and
includes:
• A department attribute.
• A function to set and display the department.
4. Demonstrate multilevel inheritance by:
• Creating an object of Professor.
• Setting values for name, subject, and department.
• Displaying the details of the professor.
Explain how multilevel inheritance works, describe the output, and discuss the
advantages and challenges of using multilevel inheritance in object-oriented
programming.
4. Student Performance System:
• Develop a student performance management system using hybrid inheritance
in C++. Implement the following class hierarchy:
1. Create a base class Student to store student details:
• Attributes: name, roll number
• Functions: set and display student details
2. Create a derived class Marks inheriting from Student to manage academic
marks:
• Attribute: marks in three subjects
• Function: calculate total academic marks
3. Create another derived class Sports to store sports performance:
• Attribute: sports marks
• Function: display sports marks
4. Create a final class Result that inherits from both Marks and Sports to
compute the overall performance:
• Function: calculate the total marks (academic + sports) and average
Implementation Requirements:
• Use Hybrid Inheritance (Combination of Multiple and Hierarchical
Inheritance).
• Demonstrate the use of virtual base class (if needed) to avoid
ambiguity.
• Implement object creation, data input, and output display.
• Show how overriding or function overloading can be applied.
Expected Output:
• Display Student details (name & roll number).
• Display academic marks, total academic marks.
• Display sports marks.
• Display overall result (total and average marks).
• Explain Hybrid Inheritance and how it prevents ambiguity.
• Discuss real-world applications of such an inheritance structure.
• Highlight advantages and potential challenges in implementing hybrid
inheritance in large-scale systems.