-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point2D.cpp
69 lines (65 loc) · 1.23 KB
/
Point2D.cpp
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 <iostream>
#include <cmath>
#include <climits>
#include <float.h>
#include <cstring>
using namespace std;
class Point2D {
private:
double x, y;
public:
// get distance between two points
double get_distance(const Point2D & p2) const {
return pow(pow(x - p2.x, 2) + pow(y - p2.y, 2), 0.5);
}
private:
bool set_x(double const new_x) {
if(DBL_MAX >= new_x && new_x >= DBL_MIN) {
x = new_x;
return true;
} else {
return false;
}
}
bool set_y(double const new_y) {
if(DBL_MAX >= new_y && new_y >= DBL_MIN) {
y = new_y;
return true;
} else {
return false;
}
}
public:
bool set_values(double const new_x, double const new_y) {
return set_y(new_y) && set_x(new_x);
}
void p_self() const {
cout << "(" << x << ", " << y << ")\n";
}
};
/*
bool Point2D::set_x(double const new_x) {
if(DBL_MAX >= new_x && new_x >= DBL_MIN) {
x = new_x;
return true;
} else {
return false;
}
}
bool Point2D::set_y(double const new_y) {
if(DBL_MAX >= new_y && new_y >= DBL_MIN) {
y = new_y;
return true;
} else {
return false;
}
}
*/
int main() {
double x, y;
char p1, p2, p3;
Point2D point;
cin >> p1 >> x >> p2 >> y >> p3;
point.set_values(x, y);
point.p_self();
}