Monday, 25 December 2017

Shape Inheritance Hierarchy


1. ADT: BasicShape
Design a BasicShape class that has the following members:
Private Member Variable:
area, a double used to hold the shape’s area.
Public Member Functions:
• getArea – return the value in the member variable area.
• calcArea – a virtual function that display a message “Basic Shape Calculate Area Function…”.
2. ADT: Circle
Design a Circle class that is derived from the BasicShape class. The Circle class should have the following members:
Private Member Variable:
centerX, a long integer used to hold the x coordinate of the circle’s center.
centerY, a long integer used to hold the y coordinate of the circle’s center.
radius, a double used to hold the circle’s radius.
Public Member Functions:
• constructor – accepts values for centerX, centerY, and radius. Should call the overridden calcArea function described
below.
• getCenterX – returns the value in centerX.
• getCenterY – returns the value in centerY.
• calcArea – calculates the area of the circle (area = 3.14159 * radius * radius) and stores the result in the inherited
member area.
3. ADT: Rectangle
Design a Rectangle class that is derived from the BasicShape class. The Rectangle class should have the following members.
Private Member Variable:
width, a long integer used to hold the width of the rectangle.
length, a long integer used to hold the length of the rectangle.
Public Member Functions:
• constructor – accepts values for width and length. Should call the overridden calcArea function described below.
• getWidth – returns the value in width.
• getLength – returns the value in length.
• calcArea – calculates the area of the rectangle (area = length * width) and stores the result in the inherited member area.
4. Main Function
Demonstrate the classes in a program that has a BasicShape pointer. Initialize it with the dynamically created object of Circle
and make call to calcArea function, then assign the BasicShape’s pointer with dynamically created Rectangle objects and
make call to calcArea function

Code Link.....
https://www.dropbox.com/s/bnrhy0rpdf5tr5v/Shape_Inheritance.cpp?dl=0

No comments:

Post a Comment

ADT: RationalNumber

Define a class for rational numbers. A rational number is “ratio-nal” number, composed of two integers with division indicated. The division...