For this project you are required to extend a C++ application that has been provided for you. This application follows a simple object-oriented example of a collection of shapes. Three shapes are supported: Circle, Rectangle, and Triangle, and functions are provided to calculate the perimeter and the area of these shapes. A base class has been defined, Shape, which allows the perimeter and area functions to be made polymorphic.
All of the code for the shapes has been provided, along with a simple menu system to drive the application. What is missing, is the collection functionality, i.e., the ability to store several shapes. For this purpose, we will be using an array, as follows:
Example of how the array will be used
The first five elements (elements zero through four) have data stored in them, and the remainder of the array has not yet been used. An additional variable, lastUsed, has been used to mark the location or boundary where elements are stored in the array. Thus to store an additional element in the array, it will be stored at the location (lastUsed + 1), and then lastUsed will be incremented to mark the new location.
The following files have been provided for the project which may not be modified:
1. [url removed, login to view], containing the main() function and several helper functions;
2. Shape.h, defining the Shape base class for the different shapes (there is no .cpp file for the Shape class);
3. Circle.h and [url removed, login to view], defining the Circle shape class;
4. Rectangle.h and [url removed, login to view], defining the Rectangle shape class; and
5. Triangle.h and [url removed, login to view], defining the Triangle shape class.
A skeleton of the class that will define the container, ShapesCollection, has been provided to guide you in this task. You will need to make the following modifications to these files:
1. ShapesCollection.h - you will need to modify the private: section to add attributes to support your functionality, note that the array is already declared, do not modify this line. No other changes are permitted to this header file; and
2. [url removed, login to view] - you will need to modify every function provided in this file/class.
The following information will guide you in each of the functions of the ShapeCollection class:
* Constructor - the creation of an array of pointers is required for this program, do not modify this line. You will however need to add lines to initialise any of the attributes you have added to the ShapesCollection.h file.
* Destructor - all dynamically allocated memory must be deleted, including the shapes provided to the AddShape function. Note that deletion of the array created in the constructor has already been provided, do not modify this line.
* AddShape() - the provided shape must be added to the array as discussed above. You should throw an exception if there is no more room in the array, e.g., throw string("ShapeCollection out of space");
* Count() - return the number of elements currently stored in the array.
* TotalAreas() - add up the areas of all the shapes stored in the array and return the total.
* TotalPerimeters() - add up the perimeters of all the shapes stored in the array and return the total.