第六周实验报告 任务三(自己做的···)
来源:互联网 发布: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");}
截图:
这个是在周末完成的···存在很多很多不足的地方···不过还是觉得能做出来很开心···
- 第六周实验报告 任务三(自己做的···)
- 第六周实验报告 任务三
- C++程序设计实验报告(四十五)---第六周任务三
- 第六周实验报告 任务三(改进)
- 第六周实验报告(任务1)
- 第六周实验报告(任务2)
- 第六周实验报告(任务3)
- 第六周实验报告(任务4)
- 第六周实验报告(任务5)
- 第六周实验报告(三)
- 第六周实验报告(三)
- 第六周实验报告(三)
- C++程序设计实验报告(四十三)---第六周任务一
- 第六周实验报告(任务三)【平面坐标点类】
- 第八周实验报告(任务三)【分数的加减乘除】
- 第十二周实验报告(任务三)【虚基类的使用】
- 第十二周实验报告(任务三)
- 第十三周实验报告(任务三)
- IT人:如何预防久坐伤身?
- 伪类测试
- yii 路由
- JSONObject与JSONArray的使用
- 一日一点RakNet(26)--Preprocessor Directives
- 第六周实验报告 任务三(自己做的···)
- 创建、移动或删除文件后不会刷新 Windows 资源管理器文件夹中的文件列表
- Objective-C名词解释
- java访问xml文件
- RadioButton创建成员变量
- margin属性
- android 模拟键盘鼠标
- 使用JAVA读写Properties属性文件
- Android实现简单的相册