您的位置:首页 > 其它

六周 项目1 体验常成员函数 没有写完!!

2014-04-01 19:12 253 查看
/*
*程序的版权和版本声明部分:
*Copyright(c)2014,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:赵加响
*完成日期:2014  年 4 月 1 日
*版本号:v1.0
*对任务及求解方法的描述部分:
*输入描述:三个点坐标
*问题描述
*/
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
class CPoint
{
private:
double x;  // 横坐标
double y;  // 纵坐标
public:
CPoint(double xx=0,double yy=0);
double Distance1(CPoint p) const;   // 两点之间的距离(一点是当前点,另一点为参数p)
double Distance0() const;            // 到原点的距离
CPoint SymmetricAxis(char style) const;//style取'x','y'和'o'分别表示按x轴, y轴, 原点对称
void input();  //以x,y 形式输入坐标点
void output(); //以(x,y) 形式输出坐标点
};
CPoint::CPoint(double xx,double yy)
{
x=xx;
y=yy;
}
CPoint CPoint::SymmetricAxis(char style) const
{
CPoint p;
switch(style)
{
case 'x':
p.x=x;
p.y=-y;
break;
case 'y':
p.x=-x;
p.y=y;
break;
case 'o':
p.x=-x;
p.y=-y;
break;
}
return p;
}
double CPoint::Distance1(CPoint p) const
{
cout<<"距离是:"<<endl;
return sqrt(pow(x-p.x,2)+pow(y-p.y,2));
}
double CPoint::Distance0() const
{
return sqrt(pow(x,2)+pow(y,2));
}
void CPoint::input()
{
cout<<"输入点的坐标:"<<endl;
cin>>x>>y;
}
void CPoint::output()
{
cout<<"该点对应的坐标为:"<<endl;
cout<<"("<<x<<","<<y<<")"<<endl;
}
int main()
{
int n;
CPoint a,b,c;
a.input();
a.output();
while(1)
{
cout<<"输入要操作的选项:"<<endl;
cout<<"1.关于X轴对称点"<<endl;
cout<<"2.关于Y轴对称点"<<endl;
cout<<"3.关于原点对称点"<<endl;
cout<<"4.到原点的距离"<<endl;
cout<<"0.退出"<<endl;
cin>>n;
switch(n)
{
case 0:
exit(0);
case 1:
b=a.SymmetricAxis('x');
b.output();
break;
case 2:
b=a.SymmetricAxis('y');
b.output();
break;
case 3:
b=a.SymmetricAxis('o');
b.output();
break;
case 4:
b=a.SymmetricAxis('o');
b.output();
cout<<a.Distance0()<<endl;
break;
default:
cout<<"输入有误,请重新输入:"<<endl;
cin>>n;
}
}
return 0;
}




感悟:暂时晕了,无论如何都不知道如何写了,等脑子清醒了在修改!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: