Point Class Reference

#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)
 
Pointoperator= (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.

Author
Brent Nash

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
newxThe initial value for the X coordinate
newyThe 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"
Parameters
rightThe Point whose coordinates should be added to the coordinates of this Point (passed by const reference).

◆ operator=()

Point & Point::operator= ( const Point other)

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"
Parameters
otherThe Point whose values should be copied into this Point (passed by const reference)
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
newxThe 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
newyThe new value for the Y coordinate

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Point a,
const Point b 
)
friend

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
aThe Point on the left side of the != operation (passed by const reference)
bThe 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]

Point operator+ ( const Point a,
const int &  b 
)
friend

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
aThe point on the left side of the + sign (passed by const reference)
bThe 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]

Point operator+ ( const Point a,
const Point b 
)
friend

Overloaded + operator for adding two points together. Not a member function, but declared as a friend so it can access member variables. This implements:

Point a, b; Point c = a + b;

Precondition
None
Postcondition
Does not change the current object
Parameters
aThe point on the left side of the + sign (passed by const reference)
bThe 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-

Point operator- ( const Point a)
friend

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
aThe 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<<

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)

Precondition
None
Postcondition
The ostream "out" will have "pt" inserted into it
Parameters
outThe output stream being modified (passed by reference...will be changed!)
ptThe 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==

bool operator== ( const Point a,
const Point b 
)
friend

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
aThe Point on the left side of the == operation (passed by const reference)
bThe 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>>

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).

Precondition
None
Postcondition
The point "a" will be changed by whatever information was extracting from the istream
Parameters
inThe input stream being modified (passed by reference...will be changed!)
ptThe 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: