第六周任务三
来源:互联网 发布:麦当劳有什么饮料知乎 编辑:程序博客网 时间:2024/06/11 23:22
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: 第二周任务
* 作 者: 杨继宇
* 完成日期: 2012 年 03 月 28 日
* 版 本 号: 01
* 对任务及求解方法的描述部分
* 输入描述:* 问题描述:设计平面坐标,计算两点之间距离,到原点的距离,关于坐标轴和原点的对称点等
* 程序输出:
* 程序头部的注释结束
*/
#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=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 { double d; d=sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y)); return d; } double CPoint::Distance0() const { double m; m=sqrt((x*x)+(y*y)); return m; } CPoint CPoint:: SymmetricAxis(SymmetricStyle style) const { double a,b; switch(style) { case axisx: a=x*(-1); cout<<"关于x轴对称"<<a<<","<<b<<endl; break; case axisy: b=y*(-1); a=x; cout<<"关于y轴对称"<<a<<","<<b<<endl; break; case point: a=x*(-1); b=y*(-1); cout<<"关于原点对称"<<a<<","<<b<<endl; break; } return 0; } void CPoint::input() { char c; cout<<"请输入坐标点(形式为x,y)"<<endl; cin>>x>>c>>y; if(c!=',') { cout<<"输入错误"<<endl; exit(1); } } void CPoint::output() { cout<<x<<","<<y<<endl; } void main() { CPoint c,p; c.input(); c.output(); p.input(); p.output(); cout<<"两点之间的距离"<<c.Distance( p)<<endl; cout<<"到原点的距离"<<c.Distance0()<<endl; c.SymmetricAxis(axisy); c.SymmetricAxis(point); system("pause"); }
- 第六周 任务三
- 第六周任务三
- 第六周任务三
- 第六周 任务三
- 第六周任务三
- 第六周任务三
- 第六周任务三
- 第六周任务三。
- 第六周任务三
- 第六周任务三
- 第六周任务三
- 第六周 任务三
- 第六周作业任务三
- 第六周任务三 坐标点
- 第六周实验报告 任务三
- 第六周上机任务(三)
- C++程序设计实验报告(四十五)---第六周任务三
- 第六周实验报告 任务三(改进)
- 第六周任务3
- B - 反正切函数的应用解题报告
- jquery插件制作进度条
- jQuery实现手风琴效果【详细注解】
- 传至播客学习笔记——函数
- 第六周任务三
- Spinner的使用
- poj 1475 Pushing Boxes
- 素女经
- 6-4 三角形类(求面积,周长,判断直角,等腰...)
- jquery插件之手风琴
- S2SH集成,数据库使用mysql,查询的时候出现字符集的错误
- jQuery实现选项卡(tabs)效果
- 一些iOS高效开源类库