-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
71 lines (60 loc) · 1.19 KB
/
Point.cpp
File metadata and controls
71 lines (60 loc) · 1.19 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
#include "Point.h"
Point::Point()
{
this->x = 0;
this->y = 0;
}
Point::Point(int a, int b)
{
this->x = a;
this->y = b;
}
bool Point::operator<(const Point& obj)
{
double d1 = sqrt(this->x * this->x + this->y * this->y);
double d2 = sqrt(obj.x * obj.x + obj.y * obj.y);
return d1 < d2;
}
//bool Point::operator > (const Point& obj)
//{
// double d1 = sqrt(this->x * this->x + this->y * this->y);
// double d2 = sqrt(obj.x * obj.x + obj.y * obj.y);
// return d1 > d2;
//}
bool Point::operator==(const Point& obj) const
{
if (this->x != obj.x || this->y != obj.y)
return false;
return true;
}
bool Point::operator!=(const Point& obj) const
{
if (this->x == obj.x && this->y == obj.y)
return false;
return true;
}
ostream& operator<<(ostream& out, const Point& obj)
{
out << "(" << obj.x << "," << obj.y << ")";
return out;
}
istream& operator>>(istream& in, Point& obj)
{
in>> obj.x >> obj.y;
return in;
}
//Point Point::operator+(const Point& obj) const
//{
// Point tmp;
// tmp.x = this->x + obj.x;
// tmp.y = this->y + obj.y;
// return tmp;
//}
//
//Point Point::operator-(const Point& obj) const
//{
// Point tmp;
// tmp.x = this->x - obj.x;
// tmp.y = this->y - obj.y;
// return tmp;
//}