Question: 1) In C++ a) Write an abstract class called Shape that has only one function called area (returning type double) and a string member variable

1) In C++

a) Write an abstract class called Shape that has only one function called area (returning type double) and a string member variable called color which is public only for classes that inherits Shape.

b)Write two concrete classes called Rectangle and Circle which both inherit the above Shape class. Rectangle has two double member variables width and length. Rectangle has an additional member function called perimeter which returns a double value. Circle has one double member variable called radius.

c) Write the main program to show how polymorphism can be used using a loop to display the area of 5 different objects of type Circle or Rectangle.

d) Show how downcasting can be used in the above polymorphic code to call the perimeter function of Rectangle

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!