写一个点类Point,每个Point对象有两个私有成员,横坐标和纵坐标.要求如下:
收藏:
0
点赞数:
0
评论数:
0
1个回答

//////////////////////////////////////////////////////////////////////////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 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

点赞数:
0
评论数:
0
关注公众号
一起学习,一起涨知识