Point Class Reference

#include <point.h>

List of all members.

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::Point (  ) 

Default constructor

Postcondition:
The X and Y coordinates are initialized to zero
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

int Point::getX (  )  const

Accessor for the X coordinate

Precondition:
None
Postcondition:
This method does not change the object
Returns:
The integer X coordinate
int Point::getY (  )  const

Accessor for the Y coordinate

Precondition:
None
Postcondition:
This method does not change the object
Returns:
The integer 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;

Precondition:
None
Postcondition:
The values in "this" will have been incremented by the values in "right"
Parameters:
right The Point whose coordinates should be added to the coordinates of this Point (passed by const reference).
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:
other The 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.
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
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

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:
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.
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:
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.)
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:
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.)
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:
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).
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:
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.
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:
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.
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:
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:
 All Classes Functions Variables Friends

Generated by  doxygen 1.6.2
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees