-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPoint.h
74 lines (69 loc) · 1.53 KB
/
Point.h
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
#ifndef POINT
#define POINT
#include<bits/stdc++.h>
using namespace std;
/*
* Structure to represent a point
*/
struct Point {
int x; //!< The x coordinate of the point
int y; //!< The y coordinate of the point
/**
* Constructor for Point class
* Initialize x and y to 0
*/
Point() {
x = 0;
y = 0;
}
/**
* Parameterized constructor of Point Class
* @param x The x coordinate of the point
* @param y The y coordinate of the point
*/
Point(int x, int y) {
this -> x = x;
this -> y = y;
}
/**
* Assignment operator overloaded for Point class
* @param p The point to be assigned
*/
void operator = (const Point &p) {
x = p.x;
y = p.y;
}
/**
* Addition operator overloaded for Point class
* @param p The point to be added
* @return A point after the coordinates are added
*/
Point operator + (const Point &p) {
return Point(x + p.x, y + p.y);
}
/**
* Subtraction operator overloaded for Point class
* @param p The point to be subtracted
* @return A point after the coordinates are subtracted
*/
Point operator - (const Point &p) {
return Point (x - p.x, y - p.y);
}
/**
* Equality operator overloaded for Point class
* @param p The point to be compared
* @return True, if points are equal else False
*/
bool operator == (const Point &p) {
return ((x == p.x) && (y == p.y));
}
/**
* Inequality operator overloaded for Point class
* @param p The point to be compared
* @return True, if points are not equal else False
*/
bool operator != (const Point &p) {
return ((x != p.x) || (y != p.y));
}
};
#endif