0% found this document useful (0 votes)
14 views2 pages

Polymorphism and Operator Overloading Tasks

Uploaded by

thirdeyeforexsl
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Polymorphism and Operator Overloading Tasks

Uploaded by

thirdeyeforexsl
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical-Based Implementation

Questions
Below are 20 practical programming tasks focused on:

 - Polymorphism (compile-time and run-time)


 - Virtual and Abstract methods
 - Operator Overloading

Set 01: Operator Overloading

1. Create a class `Person` and overload the '+' operator to combine two person names.
2. Create a class `Time` with hours and minutes. Overload the '+' operator to add two time
values correctly.
3. Write a class `Rectangle` and overload the '==' operator to check if two rectangles have
the same area.
4. Create a base class `Shape` with a virtual method `Draw()`. Override it in `Circle` and
`Square` classes.
5. Write a class `Vehicle` with an abstract method `Start()`. Implement it in `Car` and `Bike`
classes.
6. Demonstrate method overloading in a class `Calculator` with `Add(int, int)` and
`Add(double, double)`.
7. Create a `Book` class and overload the '!=' operator to compare titles.
8. Define a `ComplexNumber` class and overload the '+' and '-' operators.
9. Write a base class `Appliance` with a virtual method `TurnOn()`. Override in `Fan` and
`Light` classes.
10. Create an abstract class `Employee` with an abstract method `CalculateSalary()`.
Implement in `Manager` and `Clerk`.
11. Demonstrate what happens when you use override without marking base class method
as virtual.
12. Create a `Point` class and overload the '>' operator to compare distances from origin.
13. Write a `Student` class with overloaded constructors and method `PrintDetails()`
showing polymorphism.
14. Overload the '*' operator in a `Matrix` class to multiply two matrices.
15. Create an abstract class `Animal` with method `MakeSound()`. Implement in `Dog`, `Cat`,
and `Cow`.
16. Implement a class `Counter` and overload '++' operator to increment its value.
17. Show method overloading with different number and types of parameters in a class
`Logger`.
18. Create a `Date` class and overload '<' to compare which date is earlier.
19. Design a `Currency` class and overload '+' and '-' to add/subtract two amounts.
20. Write a class `Temperature` and overload the `==` operator to compare if two
temperatures are equal.

You might also like