Question: C++ question. Please give me a complete code. Write an abstract class called Shape. It should have pure virtual methods area and perimeter. Write a

C++ question. Please give me a complete code.

Write an abstract class called Shape. It should have pure virtual methods area and perimeter.

Write a class called Circle that inherits from Shape. It should have a double field for it's radius. It should have a set method for the radius. It should have a constructor that takes a double parameter and passes it to the set method. It should override the Shape virtual methods to return the area and perimeter of a Circle.

Write a class called Rectangle that inherits from Shape. It should have double fields for its length and width. It should have set methods for both fields. It should have a constructor that takes two double parameters and passes them to the set methods. It should override the Shape virtual methods to return the area and perimeter of a Rectangle.

Write a class called Square that inherits from Rectangle. It should have a constructor that takes one double parameter and passes it to the base class constructor for both parameters (the body of the constructor will be empty). Square will also need to override the setLength() and setWidth() functions of its base class such that if either of its dimensions is set to a new value, then both of its dimensions will be set to that new value (so that it remains a square). Hint: you can have the overridden versions call the versions in the superclass.

Write a function called averageArea that takes as a parameter a vector of Shape-pointers and returns the average area of the Shapes.

The files must be called: Shape.hpp, Circle.hpp, Circle.cpp, Rectangle.hpp, Rectangle.cpp,Square.hpp,Square.cpp and averageArea.cpp.

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!