#include <iostream>
using namespace std;
class point
{
int x,y;
public:
point(){};
point(int nx,int ny)
{
x=nx;
y=ny;
}
void show()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
void move_(int a,int b)
{
x+=a;
y+=b;
}
void move_(point &a)
{
x=a.x;
y=a.y;
}
void operator==(point a)
{
if((x==a.x)&&(y==a.y))
cout<<"是同一点"<<endl;
else
cout<<"不是同一点"<<endl;
}
void operator+=(point &a)
{
x+=a.x;y+=a.y;
}
point operator+(point a)
{
point add;
add.x=x+a.x;
add.y=y+a.y;
return add;
}
void operator++()
{
x++;
y++;
}
void operator++(int a=0)
{
x++;
y++;
}
};
int main()
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
point a(x1,y2),b(x2,y2);
a==b;
a+=b;
a.show();
b.show();
a=a+b;
a.show();
a++;
a.show();
++a;
a.show();
}
输入:
1 1
2 2
理想输出:
不是同一点
(3,3)
(2,2)
(5,5)
(6,6)
(7,7)
帮你修改好了
#include <iostream>
using namespace std;
class point
{
int x, y;
public:
point() : x(0), y(0){};
point(int nx, int ny)
{
x = nx;
y = ny;
}
void show()
{
cout << "(" << x << "," << y << ")" << endl;
}
void move_(int a, int b)
{
x += a;
y += b;
}
void move_(point &a)
{
x += a.x;
y += a.y;
}
bool operator==(point a) const
{
return x == a.x && y == a.y;
}
point &operator+=(point &a)
{
x += a.x;
y += a.y;
return *this;
}
point operator+(point a)
{
point add = *this;
add.x = x + a.x;
add.y = y + a.y;
return add;
}
point &operator++()
{
x++;
y++;
return *this;
}
point operator++(int)
{
point t = *this;
x++;
y++;
return t;
}
};
int main()
{
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
point a(x1, y1), b(x2, y2);
if (a == b)
cout << "是同一点" << endl;
else
cout << "不是同一点" << endl;
a += b;
a.show();
b.show();
a = a + b;
a.show();
a++;
a.show();
++a;
a.show();
return 0;
}