//////////////////////////////////////////////////////////////////////////Point.h
#include
#include
using namespace std;
class Point
{
private:
double x,y;
public:
Point();
Point(double x,double y);
Point(Point &p);
bool operator == (Point &p);
bool operator != (Point &p);
Point operator += (Point &p);
Point operator -= (Point &p);
Point operator + (Point &p);
Point operator - (Point &p);
friend inline ostream & operator <<(ostream & os,Point &p)
{
os<
os<<"此点的x坐标:"<
}
};
////////////////////////////////////////////////////////////////////////////////Point.cpp
#include "Point.h"
Point::Point()
{
this->x = 0;
this->y = 0;
}
Point::Point(double x,double y)
{
this->x = x;
this->y = y;
}
Point::Point(Point &p)
{
this->x = p.x;
this->y = p.y;
}
bool Point::operator == (Point &p)
{
if(this->x == p.x && this->y == p.y)
return true;
else
return false;
}
bool Point::operator != (Point &p)
{
if(this->x != p.x && this->y != p.y)
return true;
else
return false;
}
Point Point::operator += (Point &p)
{
this->x += p.x;
this->y += p.y;
return *this;
}
Point Point::operator -= (Point &p)
{
this->x -= p.x;
this->y -= p.y;
return *this;
}
Point Point::operator + (Point &p)
{
Point t;
t.x = this->x + p.x;
t.y = this->y + p.y;
return t;
}
Point Point::operator - (Point &p)
{
Point t;
t.x = this->x - p.x;
t.y = this->y - p.y;
return t;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////main.cpp
#include "Point.h"
int main()
{
Point p1;
Point p2(2.43,5.33);
Point p3(p2);
cout<
if(p2 == p3)
cout<<"=="<
cout<<"!="<
cout<<"!="<
cout<<"=="<
p1 -= p2;
cout<
Point p4 = p3 + p2;
Point p5 = p2 - p1;
cout<
system("pause");
return 0;
}
这个不给分就太不够意思了。。。。