Demo entry 6761856

233

   

Submitted by anonymous on Oct 05, 2018 at 11:13
Language: C++. Code size: 724 Bytes.

// 矢量类型

struct vct
{
	double x, y;
	vct() : x(0), y(0) {}
	vct(double xx, double yy) : x(xx), y(yy) {}
	double mod()											// 矢量的模
	{
		return sqrt(x * x + y * y);
	}
	vct operator + (vct a) const
	{
		return vct(x + a.x, y + a.y);
	}
	vct operator - () const
	{
		return vct(-x, -y);
	}
	vct operator - (vct a) const
	{
		return *this + (-a);
	}
	vct operator * (double a) const
	{
		return vct(x * a, y * a);
	}
	vct operator / (double a) const
	{
		return vct(x / a, y / a);
	}
	friend vct operator * (double a, const vct & v);
	vct operator += (vct a)
	{
		x += a.x;
		y += a.y;
		return *this;
	}
	vct operator -= (vct a)
	{
		x -= a.x;
		y -= a.y;
		return *this;
	}
};

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).