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

来源:互联网 发布:php取出数组最大值 编辑:程序博客网 时间:2024/05/20 01:09

源代码:

#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");}


截图:

 

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

原创粉丝点击