#include <point.h>
Public Member Functions | |
Point () | |
Point (int newx, int newy) | |
int | getX () const |
int | getY () const |
void | setX (int newx) |
void | setY (int newy) |
Point & | operator= (const Point &other) |
void | operator+= (const Point &right) |
Friends | |
Point | operator+ (const Point &a, const Point &b) |
Point | operator+ (const Point &a, const int &b) |
std::ostream & | operator<< (std::ostream &out, const Point &pt) |
std::istream & | operator>> (std::istream &in, Point &pt) |
bool | operator== (const Point &a, const Point &b) |
bool | operator!= (const Point &a, const Point &b) |
Point | operator- (const Point &a) |
A basic class to represent a point somewhere in 2D space.
Point::Point | ( | ) |
Default constructor
Point::Point | ( | int | newx, | |
int | newy | |||
) |
Overloaded constructor
newx | The initial value for the X coordinate | |
newy | The initial value for the Y coordinate |
int Point::getX | ( | ) | const |
Accessor for the X coordinate
int Point::getY | ( | ) | const |
Accessor for the Y coordinate
void Point::operator+= | ( | const Point & | right | ) |
Overloaded += opreator used to increment the values in the current point by the coordinate values in another point. This will take each of the coordinates in "right" and add them to each of the coordinates in "this" respectively. This implements:
Point a, b; a += b;
Overloaded = operator used to set two Points equal to each other. Declared as a member function because it changes the current object. This implements:
Point a, b; a = b;
other | The Point whose values should be copied into this Point (passed by const reference) |
void Point::setX | ( | int | newx | ) |
Mutator for the X coordinate
newx | The new value for the X coordinate |
void Point::setY | ( | int | newy | ) |
Mutator for the Y coordinate
newy | The new value for the Y coordinate |
Overloaded operator to compare two Points for inequality. Two points are not equal if any of their individual member coordinates are different. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a, b; if(a != b)
a | The Point on the left side of the != operation (passed by const reference) | |
b | The Point on the right side of the != operation (passed by const reference) |
Overloaded + operator for adding an integer to a point. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a; int x; Point c = a + x;
a | The point on the left side of the + sign (passed by const reference) | |
b | The int on the right side of the + sign (passed by const reference) |
Overloaded + operator for adding two points together. Not a member function, but declared as a friend so it can access member variables. This implements:
a | The point on the left side of the + sign (passed by const reference) | |
b | The point on the right side of the + sign (passed by const reference) |
Overloaded unary operator negation operator to multiply each coordinate of the input Point by -1. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a, b; a = -b;
a | The Point on the right side of the - operation (passed by const reference) |
std::ostream& operator<< | ( | std::ostream & | out, | |
const Point & | pt | |||
) | [friend] |
Overloaded << operator for inserting a point in an output stream. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a; cout << a;
Outputs a Point in the form "(x,y)" (no quotes)
out | The output stream being modified (passed by reference...will be changed!) | |
pt | The point being inserted into the output stream (passed by const reference) |
Overloaded operator to compare two Points for equality. Two points are equal if each of their individual member coordinates are equal. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a, b; if(a == b)
a | The Point on the left side of the == operation (passed by const reference) | |
b | The Point on the right side of the == operation (passed by const reference) |
std::istream& operator>> | ( | std::istream & | in, | |
Point & | pt | |||
) | [friend] |
Overloaded >> operator for extracting a point from an input stream. Not a member function, but declared as a friend so it can access member variables. This implements:
Point a; cin >> a;
Expects a Point to be entered in the form "X Y" (no quotes).
in | The input stream being modified (passed by reference...will be changed!) | |
pt | The point having input stream information extracted into it (passed by reference...will be changed!) |