# 第六周实验报告 任务三（自己做的···）

#include<iostream>

#include<cmath>

using namespace std;

enum SymmetricStyle { axisx,axisy,point};//分别表示按x轴, y轴, 原点对称

class CPoint
{
private:

mutable double x;  // 横坐标

mutable double y;  // 纵坐标

public:

CPoint(double xx=0,double yy=0);

double Distance(CPoint p) const;   // 两点之间的距离(一点是当前点，另一点为参数p)

double Distance0() const;          // 到原点的距离

CPoint SymmetricAxis(SymmetricStyle style) const;// 返回对称点

void input();  //以x,y 形式输入坐标点

void output(); //以(x,y) 形式输出坐标点
};

CPoint::CPoint(double xx, double yy)
{
x = xx;

y = yy;
}

double CPoint::Distance(CPoint p) const
{
return(sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)));
}

double CPoint::Distance0() const
{
return(sqrt((x - 0) * (x - 0) + (y - 0) * (y - 0)));
}

void CPoint::input()
{
char z;

while(1)
{
cout << "请以 x , y 形式输入坐标点:";

cin >> x >> z >> y;

if(z == ',')
{
break;
}

else
{
cout<< "输入格式有误!!!" << endl;
}
}
}

void CPoint::output()
{
cout << "(" << x << "," << y << ")" << endl;
}

CPoint CPoint::SymmetricAxis(SymmetricStyle style) const
{
double z;

switch(style)
{
case axisx: y = -y; break;

case axisy: x = -x; break;

case point: z = x; x = -y; y = -z; break;

default: break;
}
return style;
}

void main()
{
CPoint a,  b(1,2);

a.input();

cout << "输入点到原点的距离为:" << a.Distance0() << endl;

cout << "输入点到b点(1,2)的距离为:" << a.Distance(b) <<endl;

a.SymmetricAxis(axisx);

cout << "输入点关于x轴的对称点为:";

a.output();

a.SymmetricAxis(axisx);

a.SymmetricAxis(axisy);

cout << "输入点关于y轴的对称点为:";

a.output();

a.SymmetricAxis(axisy);

a.SymmetricAxis(point);

cout << "输入点关于原点的对称点为:";

a.output();

system("pause");
}

03-28 464

03-27 293

03-28 332

03-26 233

03-28 329

03-26 259

03-26 549

03-27 539

03-24 284

03-27 439