首页 > 其他分享 >Point Class

Point Class

时间:2022-08-30 21:00:48浏览次数:37  
标签:return Point int void distanceTo include Class

//Point.h
#ifndef POINT_H
#define POINT_H

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
class Point {
public:
	Point() :x(0), y(0) {}
	Point(int x, int y) :x(x), y(y) {};
	void setX(int x) {
		this->x = x;
	}
	int getX() {
		return this->x;
	}
	void setY(int y) {
		this->y = y;
	}
	int getY() {
		return this->y;
	}
	void print() {
		cout << "(" << this->x << ", " << this->y << ")";
	}
	void moveRight(int offset) {
		this->x = this->x + offset;
	}
	void moveDown(int offset) {
		this->y = this->y + offset;
	}

	double distanceTo();
	bool operator > (Point& point2);
	~Point() {}
private:
	int x;
	int y;
};
double Point::distanceTo() {
	return sqrt((this->x * this->x) + (this->y * this->y));
}
bool Point::operator > (Point& point2) {
	if (this->distanceTo() > point2.distanceTo()) {
		return true;
	} else {
		return false;
	}
}

#endif

标签:return,Point,int,void,distanceTo,include,Class
From: https://www.cnblogs.com/catting123/p/16640781.html

相关文章