0% found this document useful (0 votes)
3 views1 page

Virtual Function Assignment

The document outlines an assignment to create a C++ program that defines an abstract base class 'Shape' with pure virtual functions for drawing shapes and calculating their area. It requires the implementation of two derived classes, 'Circle' and 'Rectangle', each with specific properties and methods. Additionally, the main function must instantiate these classes and demonstrate their functionality by calling the draw and area calculation methods.

Uploaded by

josephwelch042
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)
3 views1 page

Virtual Function Assignment

The document outlines an assignment to create a C++ program that defines an abstract base class 'Shape' with pure virtual functions for drawing shapes and calculating their area. It requires the implementation of two derived classes, 'Circle' and 'Rectangle', each with specific properties and methods. Additionally, the main function must instantiate these classes and demonstrate their functionality by calling the draw and area calculation methods.

Uploaded by

josephwelch042
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
You are on page 1/ 1

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]

You might also like