支持以下图中的运算

类声明:

class Point2 {
public:
	Point2();
	~Point2();
	Point2(ldouble a);
	Point2(ldouble a, ldouble b);
	Point2(const Point2& p);
	Point2 operator+(const Point2& p) const;
	Point2& operator+=(const Point2& p);
	Point2 operator-(const Point2& p) const;
	Point2& operator-=(const Point2& p);
	Point2 operator*(ldouble a) const;
	Point2& operator*=(ldouble a);
	Point2 operator/(ldouble f) const;
	Point2& operator/=(ldouble f);
	Point2 operator-() const;
	Point2& operator=(const Point2& p);
	bool operator==(const Point2& p) const;
	bool operator!=(const Point2& p) const;
	friend ldouble distance(const Point2& p1, const Point2& p2);
	friend ldouble distance_squared(const Point2& p1, const Point2& p2);
	friend Point2 operator*(ldouble a, const Point2& p);
	friend std::ostream& operator<<(std::ostream& os, const Point2& p);
	friend std::istream& operator>>(std::istream& is, Point2& p);
	ldouble x, y;
};

class Point3 {
public:
	Point3();
	~Point3();
	Point3(ldouble a);
	Point3(ldouble a, ldouble b, ldouble c);
	Point3(const Point2& p);
	Point3(const Point3& p);
	Point3 operator+(const Vector3& v) const;
	Point3& operator+=(const Vector3& v);
	Vector3 operator-(const Point3& p) const;
	Point3 operator-(const Vector3& v) const;
	Point3& operator-=(const Vector3& v);
	Point3 operator*(ldouble a) const;
	Point3& operator*=(ldouble a);
	Point3 operator/(ldouble f) const;
	Point3& operator/=(ldouble f);
	Point3 operator-() const;
	Point3& operator=(const Point3& p);
	bool operator==(const Point3& p) const;
	bool operator!=(const Point3& p) const;
	friend ldouble distance(const Point3& p1, const Point3& p2);
	friend ldouble distance_squared(const Point3& p1, const Point3& p2);
	friend Point3 operator*(ldouble a, const Point3& p);
	friend std::ostream& operator<<(std::ostream& os, const Point3& p);
	friend std::istream& operator>>(std::istream& is, Point3& p);
	ldouble x, y, z;
};

  

实现还是作为练习,图中已经写明了运算了。

posted on 2020-03-31 03:31  dalgleish  阅读(1012)  评论(0编辑  收藏  举报