/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 高中亚
* 完成日期: 2012 年 03 月 28 日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
#include <iostream>
#include <cmath>
using namespace std;
enum SymmetricStyle { axisx,axisy,point }; //分别表示按x轴,y轴,原点对称。
class CPoint
{
private:
double x;
double y;
public:
CPoint(double xx=0, double yy=0);//:x(xx),y(yy){}可以用另一种方法定义的
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
{
double d;
d = sqrt(pow((p.x - x),2)+pow((p.y - y),2));
return d;
}
double CPoint::Distance0() const
{
double d;
d = sqrt(pow(x,2)+pow(y,2));
return d;
}
void CPoint::input()
{
char c;
cout<<"请以(x,y)形式输入"<<endl;
while(1)
{
cin>>x>>c>>y;
if(c ==',')
break;
cout<<"输入格式不正确,重新输入"<<endl;
}
}
void CPoint::output()
{
cout<<"("<<x<<","<<y;
cout<<")"<<endl;
}
CPoint CPoint::SymmetricAxis(SymmetricStyle style) const //定义为一个类类型的枚举类型函数
{
CPoint p;
switch(style)
{
case axisx:
p.y=-y;
p.x= x;
break;
case axisy:
p.x=-x;
p.y= y;
break;
case point:
p.x=-x;
p.y=-y;
}
return p; //返回值是个类p
}
int main()
{
CPoint a,b;
a.input();
b.input();
cout<<"两点间的距离为"<<a.Distance(b);
cout<<"点到原点的距离为"<<a.Distance0()<<endl;
cout<<"关于x轴的对称点"<<endl;
a.SymmetricAxis(axisx).output();
cout<<"关于y轴的对称点"<<endl;
a.SymmetricAxis(axisy).output();
cout<<"关于原点的对称点"<<endl;
a.SymmetricAxis(point).output();
system("pause");
return 0;
}