Virtual Function Assignment
Virtual Function Assignment
email:[email protected]
Write a C++ program that defines a Shape class as an abstract base class with two pure
virtual functions: draw() and calculateArea(). The draw() function should display a
message indicating the type of shape being drawn, and the calculateArea() function
should return the area of the shape.
i. Implement two derived classes, Circle and Rectangle, that inherit from the
Shape class. The Circle class should have a private member variable radius,
and the Rectangle class should have private member
variables width and height. Both derived classes should provide their own
implementations of the draw() and calculateArea() functions. [3 marks]
ii. In the main function, create an instance of the Circle class with a radius of 5.0
and an instance of the Rectangle class with a width of 3.0 and a height of 4.0.
Call the draw() and displayArea() functions for both objects [3 marks]