سلام!
پاسخ تمرین سری قبل را می توانید در این جا مشاهده نمایید.
#include <iostream>
#include <cstdio>
using namespace std;
class Point{
friend void set(Point*, double = 0, double = 0);
private:
double _x, _y;
void setX(double);
void setY(double);
public:
Point(double = 0, double = 0);
double x() const;
double y() const;
void print();
};
Point::Point(double x, double y){
set(this, x, y);
}
void Point::setX(double x){
this->_x = x;
}
void Point::setY(double y){
this->_y = y;
}
double Point::x() const{
return this->_x;
}
double Point::y() const{
return this->_y;
}
void Point::print(){
printf("(%g, %g)", this->x(), this->y());
}
void set(Point *point, double x, double y){
point->setX(x);
point->setY(y);
}
Point operator+(Point p1, Point p2){
return Point(p1.x() + p2.x(), p1.y() + p2.y());
}
Point operator-(Point p1, Point p2){
return Point(p1.x() - p2.x(), p1.y() - p2.y());
}
Point operator*(Point p1, Point p2){
return Point(p1.x() * p2.x(), p1.y() * p2.y());
}
Point operator/(Point p1, Point p2){
return Point(p1.x() / p2.x(), p1.y() / p2.y());
}
Point operator+(int a, Point p){
return Point(p.x() + a, p.y() + a);
}
Point operator+(Point p, int a){
return Point(p.x() + a, p.y() + a);
}
bool operator>(Point p1, Point p2){
if (p1.x() > p2.x())
return true;
if (p1.y() > p2.y())
return true;
return false;
}
bool operator==(Point p1, Point p2){
return p1.x() == p2.x() && p1.y() == p2.y();
}
bool operator!=(Point p1, Point p2){
return !(p1 == p2);
}
bool operator<(Point p1, Point p2){
return !(p1 > p2) && !(p1 == p2);
}
bool operator<=(Point p1, Point p2){
return !(p1 > p2);
}
bool operator>=(Point p1, Point p2){
return !(p1 < p2);
}
int main(){
return 0;
}
موفق باشید!