第六周实验报告 任务三(自己做的···)

源代码:

#include<iostream>

#include<cmath>

using namespace std;

enum SymmetricStyle { axisx,axisy,point};//分别表示按x轴, y轴, 原点对称

class CPoint
{
private:
	
	mutable double x;  // 横坐标
	
	mutable double y;  // 纵坐标
	
public:
	
	CPoint(double xx=0,double yy=0);
	
	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
{
	return(sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)));
}

double CPoint::Distance0() const
{
	return(sqrt((x - 0) * (x - 0) + (y - 0) * (y - 0)));
}

void CPoint::input()
{
	char z;
	
	while(1)
	{ 
		cout << "请以 x , y 形式输入坐标点:";

		cin >> x >> z >> y;
		
		if(z == ',')
		{
			break;
		}
		
		else
		{
			cout<< "输入格式有误!!!" << endl;
		}
	}
}

void CPoint::output()
{
	cout << "(" << x << "," << y << ")" << endl;
}

CPoint CPoint::SymmetricAxis(SymmetricStyle style) const
{
	double z;
	
	switch(style)
	{
	case axisx: y = -y; break;
		
	case axisy: x = -x; break;
		
	case point: z = x; x = -y; y = -z; break;
		
	default: break;
	}
	return style;
}

void main()
{
	CPoint a,  b(1,2);
	
	a.input();
	
	cout << "输入点到原点的距离为:" << a.Distance0() << endl;
	
	cout << "输入点到b点(1,2)的距离为:" << a.Distance(b) <<endl;
	
	a.SymmetricAxis(axisx);
	
    cout << "输入点关于x轴的对称点为:";
	
	a.output();
	
	a.SymmetricAxis(axisx);
	
	a.SymmetricAxis(axisy);
	
	cout << "输入点关于y轴的对称点为:";
	
	a.output();
	
	a.SymmetricAxis(axisy);
	
	a.SymmetricAxis(point);
	
	cout << "输入点关于原点的对称点为:";
	
	a.output();

	system("pause");
}


截图:

 

这个是在周末完成的···存在很多很多不足的地方···不过还是觉得能做出来很开心···

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值