第六周任务三

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* 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”标签跳过

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值