#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) |
Detailed Description
A basic class to represent a point somewhere in 2D space.
Constructor & Destructor Documentation
◆ Point() [1/2]
Point::Point | ( | ) |
Default constructor
- Postcondition
- The X and Y coordinates are initialized to zero
◆ Point() [2/2]
Point::Point | ( | int | newx, |
int | newy | ||
) |
Overloaded constructor
- Parameters
-
newx The initial value for the X coordinate newy The initial value for the Y coordinate
Member Function Documentation
◆ getX()
int Point::getX | ( | ) | const |
Accessor for the X coordinate
- Precondition
- None
- Postcondition
- This method does not change the object
- Returns
- The integer X coordinate
◆ getY()
int Point::getY | ( | ) | const |
Accessor for the Y coordinate
- Precondition
- None
- Postcondition
- This method does not change the object
- Returns
- The integer Y coordinate
◆ operator+=()
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;
- Precondition
- None
- Postcondition
- The values in "this" will have been incremented by the values in "right"
◆ operator=()
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;
- Precondition
- None
- Postcondition
- The values stored inside "this" will be changed to the values stored inside of "other"
- Returns
- A reference to "this" so that we can chain '=' operations together.
◆ setX()
void Point::setX | ( | int | newx | ) |
Mutator for the X coordinate
- Precondition
- None
- Postcondition
- The X coordinate will be updated to the value of "newx"
- Parameters
-
newx The new value for the X coordinate
◆ setY()
void Point::setY | ( | int | newy | ) |
Mutator for the Y coordinate
- Precondition
- None
- Postcondition
- The Y coordinate will be updated to the value of "newy"
- Parameters
-
newy The new value for the Y coordinate
Friends And Related Function Documentation
◆ operator!=
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)
- Precondition
- None
- Postcondition
- No changes
- Parameters
-
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)
- Returns
- A bool value of "true" if the Points are not equal. False otherwise.
◆ operator+ [1/2]
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;
- Precondition
- None
- Postcondition
- Does not change the current object
- Parameters
-
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)
- Returns
- A new point object created by adding b to each of the coordinates of a (e.g. a.x + b, a.y + b, etc.)
◆ operator+ [2/2]
Overloaded + operator for adding two points together. Not a member function, but declared as a friend so it can access member variables. This implements:
- Precondition
- None
- Postcondition
- Does not change the current object
- Parameters
-
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)
- Returns
- A new point object created by adding together the individual coordinates from a & b (e.g. a.x + b.x, a.y + b.y, etc.)
◆ operator-
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;
- Precondition
- None
- Postcondition
- No changes
- Parameters
-
a The Point on the right side of the - operation (passed by const reference)
- Returns
- A point whose values are the negation of the values in the input Point a (e.g. if (5,6) is input, then (-5,-6) should be returned).
◆ operator<<
|
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)
- Precondition
- None
- Postcondition
- The ostream "out" will have "pt" inserted into it
- Parameters
-
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)
- Returns
- A reference to the input parameter "out" so that we can chain multiple << operators together.
◆ operator==
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)
- Precondition
- None
- Postcondition
- No changes
- Parameters
-
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)
- Returns
- A bool value of "true" if the Points are equal. False otherwise.
◆ operator>>
|
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).
- Precondition
- None
- Postcondition
- The point "a" will be changed by whatever information was extracting from the istream
- Parameters
-
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!)
- Returns
- A reference to the input parameter "in" so that we can chain multiple >> operators together.
The documentation for this class was generated from the following files:
- /home/awalsh128/doxygen-themes/example_src/point.h
- /home/awalsh128/doxygen-themes/example_src/point.cpp