Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions