/* The Point class Implementation file (Point.cpp) */ #include "Point.h" #include using namespace std; // Constructor - The default values are specified in the declaration Point::Point(int x, int y) : x(x), y(y) { } // Getters int Point::getX() const { return x; } int Point::getY() const { return y; } // Setters void Point::setX(int x) { this->x = x; } void Point::setY(int y) { this->y = y; } // Overload ++Prefix, increase x, y by 1 Point & Point::operator++() { ++x; ++y; return *this; } // Overload Postfix++, increase x, y by 1 const Point Point::operator++(int dummy) { Point old(*this); ++x; ++y; return old; } // Overload Point + int. Return a new Point by value const Point Point::operator+(int value) const { return Point(x + value, y + value); } // Overload Point + Point. Return a new Point by value const Point Point::operator+(const Point & rhs) const { return Point(x + rhs.x, y + rhs.y); } // Overload Point += int. Increase x, y by value Point & Point::operator+=(int value) { x += value; y += value; return *this; } // Overload Point += Point. Increase x, y by rhs Point & Point::operator+=(const Point & rhs) { x += rhs.x; y += rhs.y; return *this; } // Overload << stream insertion operator ostream & operator<<(ostream & out, const Point & point) { out << "(" << point.x << "," << point.y << ")"; return out; } // Overload >> stream extraction operator istream & operator>>(istream & in, Point & point) { cout << "Enter x and y coord: "; in >> point.x >> point.y; return in; } // Overload int + Point. Return a new point const Point operator+(int value, const Point & rhs) { return rhs + value; // use member function defined above }