Question
In C++, implement a Polygon class and write a main driver program to allow for the instantiation of mutliple polygon objects each of varying length
In C++, implement a Polygon class and write a main driver program to allow for the instantiation of mutliple polygon objects each of varying length and width.
The definition of the Polygon class should be in an individual header (.h) file and the implementation of the class's methods should be in an individual source (.cpp) file.
The class should be designed around the following characteristics:
The name of the class should be Polygon.
The class should be composed of at least the following (data) members:
MAX_POLYGONS, (static constant) data member to indicate the maximum possible objects that can be instantiated for this class. The assigned value should be 25.
numPolygons, (static) data member to indicate the number of polygons physically instantiated.
length, data member to represent the length of the polygon.
width, data member to represent the width of the polygon.
perimeter, this value will be calculated based on the values of length and width.
area, this value will be calculated based on the values of length and width.
MIN, (constant) data member that represents the minimum possible value for the length and width of a specific polygon object. Unless otherwise specified, this value should be set to DEFAULT_MIN.
MAX, (constant) data member that represents the maximum possible value for the length and width of a specific polygon object. Unless otherwise specified, this value should be set to DEFAULT_MAX.
DEFAULT_MIN, (static constant) represents the default value to initialize the MIN data member of each object when a specific minimum value is not passed. The value assigned should be 10.
DEFAULT_MAX, (static constant) represents the default value to initialize the MAX data member of each object when a specific maximum value is not passed. The value assigned should be 100..
The class should include at least the following methods:
Default Constructor, initializes each data member with appropriate default values.
Constructor, initializes the object with specific values for the MIN and MAX data members. Remaining data members should be initialized appropriately.
Constructor, initializes the object with specific values for length, width, MIN, and MAX. Remaining data members should be initialized appropriately.
Destructor, clears out all the data members and adjusts any class level data as needed.
A method to populate the data members {length, width} from external (user) input.
Mutator methods for each data member or logical groupings, as necessary. Note that these methods should ensure the integrity of the object and should not allow data to be saved that is not appropriate for that data member. Example, length and width must be between MIN and MAX inclusive.
A method to calculate the area of the polygon.
A method to calculate the perimeter of the polygon.
Note that these methods can be invoked implicitly when an object is constructed with specific values for length and width or explicitly by the application after the values for length and width have been set.
A method to display the pertinent data members {length, width, area, perimeter}.
A method to draw a polygon of the specified length and width. You can use any character to draw the shape (i.e. border) of the polygon.
The class should allow for the instantiation of constant objects. In other words applications which use this class should be able to create polygon objects of type const.
The program should instantiate an array of pointers to objects of the Polygon class. The class data member MAX_POLYGONS should be used to declare the size of the array. The program should provide the user with the following options:
1. Build a new polygon object and assign it as the next entry in the array.
2. Draw the shape corresponding to any one of the polygons which have been built. The user can specify the desired polygon by using the objects numerical position in the array (i.e. 1 for the first polygon object, 3 for the third etc.)
3. Show a summary of information of all the polygons that have been built. The summary should include detail information about each polygon. This informaion should include the length, width, area and perimeter. The summary should also display class level statistics, inclusing how many polygons were built as well as the average area and average perimeter of all the polygons. Note that these statistics should be maintained by the class and not by the driver program.
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