Question: For this lab we will create a container class using pointers. Our container is called Line and the Line container holds the Point class. The

For this lab we will create a container class using pointers. Our container is called Line and the Line container holds the Point class. The Point class is very simple and already implemented. For this lab: Implement the Line member functions Use a pointer to an array of Points to hold your Point class You cannot use existing container classes. Some container classes are implemented as container adaptors and use an encapsulated object of a specific container class as its underlying container. This assignment will not implement a container adaptor. Implement a main() to test your Line class implementation. Include adding multiple Point objects to your line to force your Line to expand. The attached tar file contains the Point and Line class definitions as an Eclipse project

Below are the

- Lab10.cpp

- Line.cpp

- Point.cpp

- Line.h

- Point.h

files respectively.

//============================================================================ // Name : Lab10.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================

#include using namespace std;

int main() { cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; }

//============================================================================

/* * Line.cpp * * Created on: Nov 1, 2014 * Author: williamhooper */

#include "Line.h"

// Constructor Line::Line() { }

// Deconstructor Line::~Line() {

}

//============================================================================

//============================================================================ // Name : Point.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================

#include #include "Point.h"

using namespace std;

Point::Point(float x, float y) : x(x), y(y) {}

Point::Point(const Point & p) { x = p.x; y = p.y; }

Point& Point::operator =(const Point& rhs) { if (this != &rhs) { this->x = rhs.x; this->y = rhs.y; } return *this; }

//============================================================================

/* * Line.h * * Created on: Nov 1, 2014 * Author: williamhooper */

#ifndef LINE_H_ #define LINE_H_

#include "Point.h"

class Line { public: Line(); virtual ~Line(); void addBack(Point p); // add a Point to the end of our line unsigned int size() const; // return the number of Points in our line void clear(); // clear the Points from our line float length() const; // Length of line Point & operator[](int index); // [] operator override private: };

#endif /* LINE_H_ */

//============================================================================

// Point.h

#ifndef POINT_H_ #define POINT_H_

class Point { public: // default constructor Point(const Point & t); Point(float x = 0, float y = 0); virtual ~Point() {};

// Accessors float getX() const {return x;}; // get X value float getY() const {return y;}; // get Y value

Point& operator =( const Point& rhs );

private: float x, 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!