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 class Point { public: /** * Constructor and destructor */ Point(const double x, const double y); Point():x(0), y(0) {}; virtual ~Point(); /** * Get the x value */ double getX() const; /** * Get the y value */ double getY() const; /** * Return the distance between Points */ double distance(const Point &p) const; /** * Output the Point as (x, y) to an output stream */ friend std::ostream& operator <<(std::ostream&, const Point&); /** * Declare comparison relationships */ friend bool operator ==(const Point &lhs, const Point &rhs); friend bool operator <(const Point &lhs, const Point &rhs); /** * Declare math operators */ friend Point operator +(const Point &lhs, const Point &rhs); friend Point operator -(const Point &lhs, const Point &rhs); /** * Copy constructor */ Point(const Point & t); /** * Copy assignment */ Point& operator =( const Point& rhs ); private: double x; double y; }; #endif /* POINT_H_ */

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!