-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
96 lines (82 loc) · 1.4 KB
/
Point.cpp
File metadata and controls
96 lines (82 loc) · 1.4 KB
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
#include "Point.h"
using namespace std;
/**
* constructor for Point.
*/
Point::Point() {
}
/**
* constructor for Point.
* @param x int
* @param y int
*/
Point::Point(int x, int y) {
_x = x;
_y = y;
}
/**
* constructor for Point.
* @param p const Point*
*/
Point::Point(const Point* p) {
_x = p->_x;
_y = p->_y;
}
/**
* getting x value.
* @return int
*/
int Point::getX() const {
return Point::_x;
}
/**
* setting x value.
* @param x int
*/
void Point::setX(int x) {
_x = x;
}
/**
* getting the y value.
* @return int
*/
int Point::getY() const {
return _y;
}
/**
* setting the y value.
* @param y int
*/
void Point::setY(int y) {
_y = y;
}
/**
* return true if the nodes are equal.
* @param p Node*
* @return bool
*/
bool Point::operator==(Node* p) const {
Point* p1 = (Point*) p;
return p1->getX() == _x && p1->getY() == _y;
}
/**
* return true if the nodes are not equal.
* @param p
* @return
*/
bool Point::operator!=(Node* p) const {
Point* p1 = (Point*)p;
return !(p1->getX() == _x && p1->getY() == _y);
}
/**
* function to print nodes.
* @param output ostream&
*/
void Point::printNode(ostream& output) const {
const Point *p1 = this;
output << "(" << p1->getX() << "," << p1->getY() << ")" << endl;
}
Node *Point::operator+(Node *p) const {
Point* p1 = (Point*)p;
return new Point(_x + p1->getX(), _y + p1->getY());
}