#include // allows use of cin and cout #include "Point.h"; using namespace std; // Create a point object -- default is (0,0) if no params. Point::Point(int xVal, int yVal) : x(xVal), y(yVal) { } // default constructor - included because needed to be virtual Point::~Point(){} // return x coordinate of the point int Point::getX() const { return x; } // return y coordinate of the point int Point::getY() const { return y; } // translate the point by dx in the x direction and dy in the y. void Point::translate(int dx, int dy) { x += dx; y += dy; } // convert point to a string representation string Point::toString() const { // Magic to convert an integer to a string. asprintf is built-in. // As part of call it allocates sufficient memory to hold the converted int. char *tempx, *tempy; asprintf(&tempx, "%d",x); asprintf(&tempy, "%d",y); string xString = string(tempx); delete tempx; string yString = string(tempy); delete tempy; return "(" + xString + "," + yString + ")"; } bool Point::operator==(Point other) { return (x == other.x) && (y == other.y); } void Point::print(ostream & out) const { out << "(" << x << "," << y << ")"; }