// point class implementation #include #include #include #include #include "point.h" using namespace std; point::point(int initX, int initY) { setLocation(initX, initY); // the following line of code would not normally be included in a // constructor, but it allowed us to see what point objects were being // constructed cout << "constructing " << to_string() << endl; } string point::to_string() const { ostringstream out; out << "(" << x << ", " << y << ")"; return out.str(); } // translate the coordinates by the given amount void point::translate(int dx, int dy) { x += dx; y += dy; } double point::distance_from_origin() const { return sqrt(x * x + y * y); } int point::getX() const { return x; } int point::getY() const { return y; } void point::setLocation(int newX, int newY) { x = newX; y = newY; } ostream & operator<<(ostream & out, const point & p) { out << p.to_string(); return out; }