Pure Virtuality
You are given an abstract base class Shape.
- Create a pure virtual function area().
You are also given a derived class Rectangle that inherits from Shape.
- Implement the area() function to return area of rectangle i.e. length × width
Your task is to:
- Use the values length and width to initialize the Rectangle object.
- Demonstrate runtime polymorphism using a base class pointer.
- Return the base class pointer pointing to the derived object.
Example 1:
Input: length = 8, width = 9
Output: 72
Example 2:
Input: length = 1, width = 10
Output: 10
Now Your Turn!
Pick the correct output for the given inputInput: length = 12, width = 8
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.