-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (73 loc) · 1.68 KB
/
Copy pathmain.cpp
File metadata and controls
87 lines (73 loc) · 1.68 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
#include <iostream>
#include<cmath>
using namespace std;
class Point
{
public:
double X;
double Y;
Point() //add new constructer cuz we need to add & subtract
{
X = 0.0;
Y = 0.0;
}
Point(double x,double y)
{
X = x;
Y = y;
}
double getX()
{
return X;
return Y;
}
double getY()
{
return Y;
}
void setX (double x)
{
X = x;
}
void setY(double y)
{
Y = y;
}
double distanceTo(const Point& other) //we will perform the calculations
{
double sx= other.X - X;
double sy= other.Y - Y;
return ( sx*sx + sy*sy );
}
Point operator+(const Point & other) // the calculate for sum
{
Point other1;
other1.X = other.X + X;
other1.Y = other.Y + Y;
return other1;
}
Point operator-(const Point& other) // the calculate for subtract
{
Point other2;
other2.X = other.X - X;
other2.Y = other.Y - Y;
return other2;
}
~Point() //add the destructer
{
cout<< "thank you for using my code (:"<<endl;
}
};
int main()
{ //firstly we need write the coordinates
Point p1(1,2);
cout << "p1= " << p1.X << " . " << p1.Y << endl;
Point p2(3,4);
cout << "p2= " << p2.X << " . " << p2.Y << endl;
//now we do the calculations
double s = p1.distanceTo(p2);
Point p3 = p1 + p2;
cout << "p3= " << p3.X << " . " << p3.Y << endl;
Point p4 = p1 - p2;
cout << "p4= " << p4.X << " . " << p4.Y << endl;
}