// point class implementation #include #include #include #include "point.h" using namespace std; point::point(int init_x, int init_y) { set_location(init_x, init_y); // 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(); } 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::get_x() const { return x; } int point::get_y() const { return y; } void point::set_location(int newX, int newY) { x = newX; y = newY; } ostream & operator<<(ostream & out, const point & p) { out << p.to_string(); return out; } bool operator<(const point & lhs, const point & rhs) { return lhs.distance_from_origin() < rhs.distance_from_origin(); }