#include #include #ifdef _WIN32 #include #endif // _WIN32 and _WIN64 too using namespace std; class point{ double tab[3]; public: point() : tab{0,0,0} {} point(const double* _tab) : tab{_tab[0],_tab[1],_tab[2] } {} point(const double& a, const double& b, const double& c) : tab{a,b,c} {} double& operator [](int index) { return tab[index]; } const double& operator [](int index) const { return tab[index]; } friend ostream& operator << (ostream& out, const point& p); friend istream& operator >> (istream& in, point& p); double distance(const point p) { return sqrt(pow(p.tab[0] - tab[0], 2) + pow(p.tab[1] - tab[1], 2) + pow(p.tab[2] - tab[2], 2)); } const double distance(const point p) const { return sqrt(pow(p.tab[0] - tab[0], 2) + pow(p.tab[1] - tab[1], 2) + pow(p.tab[2] - tab[2], 2)); } const point operator+(const point& pa) const { return point(tab[0]+pa[0],tab[1]+pa[1],tab[2]+pa[2]); } const point operator-(const point& pa) const { return point(tab[0]-pa[0],tab[1]-pa[1],tab[2]-pa[2]); } }; ostream& operator << (ostream& out, const point& p) { return out << p.tab[0] << " " << p.tab[1] << " " << p.tab[2]; } istream& operator >> (istream& in, point& p) { return in >> p.tab[0] >> p.tab[1] >> p.tab[2]; } int main() { double x[2][3] = { {1.0, 1.0, 1.0}, {1.0, 2.0, 3.0} }; point p1(x[0]), p2(x[1]); const point p3(0.4, 0.2, 0.1); cout << p1 << ", " << p2 << '\n'; cout << p3[0] << ' ' << p3[1] << ' ' << p3[2] << '\n'; cout << p1.distance(point()) << endl; cout << p3.distance(p1) << endl; cout << p1 + p2 << endl; cout << p1 - p3 << endl; //cout << 3.14 * p2 << endl; //cout << p2 * 3.14 << endl; //cout << (p1 < p3) << endl; //cout << (p1 == point(1.0, 1.0, 1.0)) << endl; cin >> p1; cout << p1 << '\n'; // */ /* ???_02 cout << "\n***e0**\n"; point e0; cout << &e0 << '\n' << e0.T3() << '\n' << e0 << endl; cout << "\n***e1**\n"; point e1(x[0]); cout << x << " " << x[0] << " (" << x[0][0] << ") " << &x[0][0] << '\n'; cout << &e1 << '\n' << e1.T3() << '\n' << e1 << endl; cout << "\n***e2**\n"; point e2(e1); cout << &e2 << '\n' << e2.T3() << '\n' << e2 << endl; cout << "\n***e0**\n"; e0 = e2; cout << &e0 << '\n' << e0.T3() << '\n' << e0 << endl; // */ #ifdef _WIN32 system("PAUSE"); #endif return 0; }