/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者:刘杨
* 完成日期:2012 年 3 月 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=1,double yy=2):x(xx),y(yy){}
double Distance(CPoint p) const; // 两点之间的距离(一点是当前点,另一点为参数p)
double Distance0() const; // 到原点的距离
CPoint SymmetricAxis(SymmetricStyle style); // 返回对称点
void input(); //以x,y 形式输入坐标点
void output(); //以(x,y) 形式输出坐标点
};
void main()
{
CPoint a1;
CPoint a2;
a1.input();
a1.output();
a1.Distance0();
a1.Distance(a2);
a1.SymmetricAxis(axisx);
a1.SymmetricAxis(axisy);
a1.SymmetricAxis(point);
system("pause");
}
void CPoint::input() //以x,y 形式输入坐标点
{
char a;
cout<<"请以“x,y ”形式输入坐标点:"<<endl;
cin>>x>>a>>y;
if(a!=',')
{
exit(0);
}
}
void CPoint::output()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
double CPoint::Distance0() const
{
cout<<"到原点的距离为:"<<endl;
cout<<sqrt(x*x+y*y)<<endl;
return 0;
}
double CPoint::Distance(CPoint p) const
{
cout<<"与默认点的距离为:"<<endl;
cout<<sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y))<<endl;
return 0;
}
CPoint CPoint::SymmetricAxis(SymmetricStyle style)
{
if(style == axisx)
{
y = -y;
}
if(style == axisy)
{
x = -x;
}
if(style == point)
{
x = -x;
y = -y;
}
switch(style)
{
case axisx:cout<<"关于x轴的对称点为:("<<x<<","<<y<<")"<<endl;
break;
case axisy:cout<<"关于y轴的对称点为:("<<x<<","<<y<<")"<<endl;
break;
case point:cout<<"关于原点的对称点为:("<<x<<","<<y<<")"<<endl;
break;
default:break;
}
return 0;
}
运行结果:

经验积累:这个任务总算是在同学的帮助下做完了,没有局限于一行一行的看,划分成了几部分做完的,效果还不错。