/*
*Copyright (c) 2014, 烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:于凯
*完成日期:2015年4月8日
*版本号:v1.0
*
*/
#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
double x; // 横坐标
double y; // 纵坐标
public:
CPoint(double xx=0,double yy=0);
double Distance1(CPoint p) const; //两点间的距离
double Distance0() const; //到原点的距离
CPoint SymmetricAxis(char style) const;
void input();
void output();
};
CPoint::CPoint(double xx,double yy)
{
x=xx;
y=yy;
}
void CPoint::input()
{
cout<<"输入坐标点:";
cin>>x>>y;
}
void CPoint::output()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
double CPoint::Distance0()const
{
return(sqrt(x*x+y*y));
}
double CPoint::Distance1(CPoint p)const
{
return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
CPoint CPoint::SymmetricAxis(char style) const
{
CPoint p(this->x,this->y);
switch(style)
{
case 'x':
p.y=-y;
break;
case 'y':
p.x=-x;
break;
case 'o':
p.x=-x;
p.y=-y;
break;
}
return p;
}
int main()
{
CPoint p1,p2,p;
cout<<"输入第一二点坐标:";
p1.input();
cout<<"输入第二个点坐标:";
p2.input();
cout<<"p1到原点的距离为:"<<p1.Distance0()<<endl;
cout<<"p2到原点的距离为:"<<p2.Distance0()<<endl;
cout<<"p1与p2之间的距离为:"<<p1.Distance1(p2)<<endl;
cout<<"p1关于x轴对称坐标:";
p=p1.SymmetricAxis('x');
p.output();
cout<<"p1关于y轴对称坐标:";
p=p1.SymmetricAxis('y');
p.output();
cout<<"p1关于原点对称坐标:";
p=p1.SymmetricAxis('o');
p.output();
cout<<"p2关于x轴对称坐标:";
p=p2.SymmetricAxis('x');
p.output();
cout<<"p2关于y轴对称坐标:";
p=p2.SymmetricAxis('y');
p.output();
cout<<"p2关于原点对称坐标:";
p=p2.SymmetricAxis('o');
p.output();
return 0;
}
运行结果: