第六周任务三

来源:互联网 发布:高性能云计算 编辑:程序博客网 时间:2024/05/20 00:36
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:                              
* 作    者: 李超                             
* 完成日期:    2012  年  3   月   27  日
* 版 本 号:      01.06.03    


* 对任务及求解方法的描述部分
* 输入描述: 输入一个点坐标
* 问题描述: 设计平面坐标点类,计算两点之间距离、到原点的距离、关于坐标轴和原点的对称点
* 程序输出: 输出两点之间距离(一点为(6,7)一点为键盘输入值)、到原点的距离、关于坐标轴和原点的对称点
* 程序头部的注释结束

*/

头文件"CPoint.h"

#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 = 6, double yy = 7): x(xx), y(yy){}double Distance(CPoint p) const;   // 两点之间的距离(一点是当前点,另一点为参数p)double Distance0() const;          // 到原点的距离/*double hengzuo()//返回横坐标{return x;}double zongzuo()//返回纵坐标{return y;}*/CPoint SymmetricAxis(SymmetricStyle style) const;   // 返回对称点void input();  //以x,y 形式输入坐标点void output(); //以(x,y) 形式输出坐标点};double CPoint::Distance(CPoint p) const  // 两点之间的距离(一点是当前点,另一点为参数p){double d;//a = p.hengzuo ();//b = p.zongzuo ();d = (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);return sqrt(d);}double CPoint::Distance0()   const       // 到原点的距离{double d;d = x * x + y * y;return sqrt(d);}/*CPoint CPoint::SymmetricAxis(SymmetricStyle style) const   // 返回对称点{switch(style){case axisx:CPoint zb(x, -y);     //"zb"的初始化操作由“case”标签跳过break;case axisy:CPoint zb(-x, y);break;case point:CPoint zb(-x, -y);break;}return zb;} */                      CPoint CPoint::SymmetricAxis(SymmetricStyle style) const   // 返回对称点{CPoint zb;switch(style){case axisx:zb.x = x;zb.y = -y;break;case axisy:zb.x = -x;zb.y = y;break;case point:zb.x = -x;zb.y = -y;break;}return zb;}/*CPoint CPoint::SymmetricAxis(SymmetricStyle style) const   // 返回对称点{switch(style){case axisx:cout <<'(' <<x <<',' <<y <<')' <<"关于x轴的对称点为"<<'(' <<x <<',' <<-y <<')' <<endl;break;case axisy:cout <<'(' <<x <<',' <<y <<')' <<"关于y轴的对称点为"<<'(' <<-x <<',' <<y <<')' <<endl;break;case point:cout <<'(' <<x <<',' <<y <<')' <<"关于原点的对称点为"<<'(' <<-x <<',' <<-y <<')' <<endl;break;}return zb;}*/void CPoint::input()  //以x,y 形式输入坐标点{int a, b;cout <<"请以x,y形式输入坐标点" <<endl;cin >>a >>b;x = a;y = b;}void CPoint::output()//以(x,y) 形式输出坐标点{cout <<"坐标为:(" <<x<<',' <<y <<')' <<endl;}

主函数CPoint.cpp

#include <iostream>#include "CPoint.h"using namespace std;void main(){CPoint c1, c2;c1.input();cout <<"到原点的距离是:" <<c1.Distance0 () <<endl;cout <<"到点(6,7)的距离为:" <<c1.Distance (c2) <<endl;/*c1.SymmetricAxis (axisx);c1.SymmetricAxis (axisy);c1.SymmetricAxis (point);*/cout <<"该点关于x轴的对称点的" ;    c1.SymmetricAxis (axisx).output () ;cout <<"该点关于y轴的对称点的" ;    c1.SymmetricAxis (axisy).output () ;cout <<"该点关于原点的对称点的" ;    c1.SymmetricAxis (point).output () ;system("PAUSE");}
好令人头疼的程序啊,注释掉的竟有一半!

其中头文件中

/*CPoint CPoint::SymmetricAxis(SymmetricStyle style) const   // 返回对称点{switch(style){case axisx:CPoint zb(x, -y);     //"zb"的初始化操作由“case”标签跳过break;case axisy:CPoint zb(-x, y);break;case point:CPoint zb(-x, -y);break;}return zb;} */          
该段已被注释掉

运行时,程序提示以下错误:

"zb"的初始化操作由“case”标签跳过

希望大家帮忙解答,谢谢。