summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/point.h
blob: e13811762565b82fb568cb0199315a204b8a3fa3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * File: point.h
 * -------------
 * This file exports a class representing an integer-valued <i>x</i>-<i>y</i>
 * pair.
 */

#ifndef _point_h
#define _point_h

#include <string>

/*
 * Class: Point
 * ------------
 * This class represents an <i>x</i>-<i>y</i> coordinate point on a
 * two-dimensional integer grid.  If you need to work with real-valued points,
 * you should use the <a href="gtypes.html"><code>gtypes.h</code></a>
 * interface instead.
 */

class Point {

public:

/*
 * Constructor: Point
 * Usage: Point origin;
 *        Point pt(x, y);
 * ----------------------
 * Creates a <code>Point</code> object with the specified x and y coordinates.
 * If the coordinates are not supplied, the default constructor sets these
 * fields to 0.
 */

   Point();
   Point(int x, int y);

/*
 * Method: getX
 * Usage: int x = pt.getX();
 * -------------------------
 * Returns the <i>x</i>-coordinate of the point.
 */

   int getX() const;

/*
 * Method: getY
 * Usage: int y = pt.getY();
 * -------------------------
 * Returns the <i>y</i>-coordinate of the point.
 */

   int getY() const;

/*
 * Method: toString
 * Usage: string str = pt.toString();
 * ----------------------------------
 * Returns a string representation of the <code>Point</code> in the form
 * <code>"(x, y)"</code>.
 */

   std::string toString() const;

/*
 * Friend operator: ==
 * Usage: if (p1 == p2) ...
 * ------------------------
 * Returns <code>true</code> if <code>p1</code> and <code>p2</code>
 * are the same point.
 */

   bool operator==(const Point & p2) const;

/*
 * Friend operator: !=
 * Usage: if (p1 != p2) ...
 * ------------------------
 * Returns <code>true</code> if <code>p1</code> and <code>p2</code>
 * are different.
 */

   bool operator!=(const Point & p2) const;

/* Private section */

/**********************************************************************/
/* Note: Everything below this point in the file is logically part    */
/* of the implementation and should not be of interest to clients.    */
/**********************************************************************/

private:

/* Instance variables */

   int x;                         /* The x-coordinate of the point */
   int y;                         /* The y-coordinate of the point */

};

/*
 * Operator: <<
 * Usage: cout << pt;
 * ------------------
 * Overloads the <code>&lt;&lt;</code> operator so that it is able
 * to display <code>Point</code> values.
 */

std::ostream & operator<<(std::ostream & os, const Point & pt);

#endif