Question: Create a class hierarchy as follows: The base class is called shape and has the following data members A private data member - name (string)

Create a class hierarchy as follows:

The base class is called shape and has the following data members

A private data member - name (string) to hold the name of the shape.

A private data member - color (string) to hold the color of the shape.

A public member function display that does not return anything but displays the characteristics

of the shape (color, name, area, and other information as applicable based on the shape).

A public member function CalArea that returns double. It calculates the area of the shape. For the class shape, this member function should display an error message stating that the shape is

unknown and return 0.

Create the following derived classes using public inheritance as follows:

A circle (derived from the shape class)

A private data member called radius (double) to hold the radius of the circle.

A public member function called CalCircumference which returns double and calculates

the area of the circle.

A rectangle (derived from the shape class)

Two private data members called width(int) and height(int).

A public member function called CalPerimeter which calculates the perimeter of the

rectangle.

Create all necessary get and set functions to access the private data members. Also, redefine the member function display to produce appropriate messages based on the object type. The function should display name, color, width, height, area, and perimeter for the class rectangle and name, color, radius, area, and circumference for the class circle. For the class shape, the function displays name and color. Also, redefine CalArea to calculate the area properly for each object type.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!