point.cpp

来自「const是C++中很常用而且很灵活的一种变量,学好使用const对变成很有帮助」· C++ 代码 · 共 55 行

CPP
55
字号
// Point.cpp: implementation of the Point class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Point.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

const  Point Point::center(0,0);

Point::Point(int _x,int _y):x(_x),y(_y),center_x(0),center_y(0)
{
	x=4;
	y=6;
//	center_x=1;
}

Point::~Point()
{

}
float Point::cal_dist(Point& pt) const
{
	float x=float(this->x-pt.x);
	float y=float(this->y-pt.y);
	return (float)sqrt(x*x+y*y);
}
float Point::cal_dist(Point& pt)
{
	float x=float(this->x-pt.x);
	float y=float(this->y-pt.y);
	return (float)(fabs(x)+fabs(y));
}
void Point::set_x(int newX)
{
	x=newX;
}
void Point::set_y(int newY)
{
	y=newY;
}

int Point::get_x() const
{
	return x;
}

int Point::get_y() const
{
	return y;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?