-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork12.cpp
More file actions
58 lines (51 loc) · 922 Bytes
/
Copy pathwork12.cpp
File metadata and controls
58 lines (51 loc) · 922 Bytes
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
#include <iostream>
#include <cmath>
using namespace std;
class Point2
{
private:
double x;
double y;
public:
Point2(double n, double m)
{
x = n;
y = m;
}
double getx()
{
return x;
}
double gety()
{
return y;
}
};
class Line2
{
private:
Point2 p1;
Point2 p2;
public:
Line2(const Point2 &n,const Point2 &m) : p1(n), p2(m) {};
double Length()
{
double m, n;
m = p1.getx() - p2.getx();
n = p1.gety() - p2.gety();
double len = sqrt(m * m + n * n);
return len;
}
};
int main()
{
Point2 pt1(1.0, 1.0);
Point2 pt2(3.0, 4.0);
Line2 line(pt1, pt2);
std::cout << line.Length() << std::endl;
double x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
Line2 nLine(Point2(x1, y1), Point2(x2, y2));
std::cout << nLine.Length() << std::endl;
return 0;
}