Question: For this c++ program I need to create a container class using pointers and free store. The container is called Line and the Line container
For this c++ program I need to create a container class using pointers and free store. The container is called Line and the Line container holds the Point class. The Point class is very simple and already implemented. For this program I need to complete the following tasks.:
-Implement the new Line member functions -Use a pointer to an array of Points to hold the Point class and use free store to hold the Point objects -I need to allow the user to add as many Point objects as they wish. This will require code to expand the free store. -I cannot use existing container classes. Some container classes are implemented as container adapters and use an encapsulated object of a specific container class as its underlying container. This program will not implement a container adapter. -Implement a main() to test the Line class implementation. Include adding multiple Point objects to the line to force the Line to expand. -Include out-of-bounds checking and throw the appropriate exception when the condition occurs
Here is the Line.h file that I have so far:
/* * Line.h * */ #ifndef LINE_H_ #define LINE_H_ #include "Point.h" class Line { public: /** * Constructor and destructor */ Line(); virtual ~Line(); /** * Add a point to the end of our line. If the line contains * ten points then throw an out_of_range exception. */ void push_back(const Point& p); /** * Clear the list of points */ void clear(); /** * Return the length of the line. The length is calculated as * the sum of the distance between all points in the line. */ double length(); /** * return the number of Points in our line */ unsigned int size() const; /** * [] operator override */ Point & operator[](int index); private: unsigned int index; Point *points; }; #endif /* LINE_H_ */
and here is the point.h file:
ifndef POINT_H_ #define POINT_H_ #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
