Sample Programs-Inheritance & Functions
Sample Programs-Inheritance & Functions
1. Write a C++ program using single inheritance where a base class Person has name and age,
and a derived class Student has a roll number. Display all information.
2. Create a multilevel inheritance program where a Vehicle class is inherited by Car, and Car is
inherited by ElectricCar.
3. Use multiple inheritance where a Writer class and Singer class are inherited by a Performer
class. Show how Performer can access both base class members.
4. Hierarchical Inheritance: Create a base class Shape with a function to input and display
dimensions. Inherit Rectangle and Triangle classes and calculate area.
5. Write a program using an inline function to calculate the square of a number.
6. Write a program to calculate simple interest. Use a function with default argument for the rate
of interest.
7. Create a class Circle with a private radius. Write a friend function (outside the class) to
calculate the area of the circle.