Question
Write an abstract class called Shape. It should have pure virtual methods area and perimeter . Write a class called Circle that inherits from Shape.
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.
In a separate file, write a function called averageArea that takes as a parameter a vector of Shape-pointers and returns the average area of the Shapes.
Write a main function in its own separate file. It should create a vector of Shape-pointers, fill the vector with a variety of Circles, Rectangles and Squares, pass the vector to the averageArea function and print out the value that is returned by that function.
You should be submitting a total of nine files including the one that has your main function.
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.
In a separate file, write a function called averageArea that takes as a parameter a vector of Shape-pointers and returns the average area of the Shapes.
Write a main function in its own separate file. It should create a vector of Shape-pointers, fill the vector with a variety of Circles, Rectangles and Squares, pass the vector to the averageArea function and print out the value that is returned by that function.
You should be submitting a total of nine files including the one that has your main function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started