// ΛΥΣΕΙΣ ΘΕΜΑΤΩΝ ΣΕΠΤΕΜΒΡΗ 2016 // ΘΕΜΑ 4. #include #include using namespace std; class Point{ private: float x,y,z; public: Point(float x1, float y1, float z1){ x = x1; y = y1; z = z1; } Point(Point const &p){ x = p.x; y = p.y; z = p.z; } ~Point(){ cout << "Deleting Point(" << x << "," << y << "," << z << ")\n"; } Point symmetric(){ Point p(0,0,0); p.x = -x; p.y = -y; p.z = -z; return p; } float distance(Point p){ return sqrt(pow(x- p.x,2) + pow(y- p.y,2) + pow(z- p.z,2)); } Point &operator= (const Point &p){ if (this != &p){ x = p.x; y = p.y; z = p.z; } return (*this); } bool operator== (const Point &p){ return (x == p.x && y == p.y && z == p.z); } friend void print(Point); }; void print(Point p){ cout << "Point(" << p.x << "," << p.y << "," << p.z << ")\n"; } int main(){ Point A(1,1,1), B(2,2,2), *c = new Point(3,3,3); print(A); print(B); cout << A.distance(B) << endl << B.distance(*c) << endl << c->distance(A) << endl; cout << sqrt(3) << endl << sqrt(3) << endl << sqrt(12) << endl; cout << "Testing if A == B\n"; if (A == B){ cout << "same points \n"; } else { cout << "different points\n"; } B = A; cout << "Testing again, if A == B\n"; if (A == B){ cout << "same points \n"; } else { cout << "different points\n"; } print(B); print(A.symmetric()); print(A); print(B); print(*c); c->~Point(); // delete c; return 0; }