第六周实验
来源:互联网 发布:淘宝轮播图代码 编辑:程序博客网 时间:2024/05/22 14:18
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 李冠绩
* 完成日期: 2012 年 3 月 28 日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:设计平面坐标点类,计算两点之间的距离,到原点的距离,关于坐标轴和原点的对称点等,其中使用了枚举
* 程序输出:
* 程序头部的注释结束
*/
注:由于没安装vs2008,用的vc。。见谅
#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; // 两点之间的距离
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;
}
// 输入坐标点
void CPoint::input()
{
char m;
cout<<"请输入坐标点(格式为x,y ):";
while(1)
{
cin>>x>>m>>y;
if (m!=',')
cout<<"输入的格式不正确,请重新输入";
break;
}
}
// 输出坐标点
void CPoint::output()
{
cout<<"("<<x<<", "<<y<<")"<<endl;
}
// 求两点之间的距离
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 d;
d=sqrt(x*x+y*y);
return d;
}
// 求对称点
CPoint CPoint::SymmetricAxis(SymmetricStyle style) const
{
CPoint p(this->x,this->y);
switch(style)
{
case axisx:
p.y=-y; break;
case axisy:
p.x=-x; break;
case point:
p.x=-x;p.y=-y;
}
return p;
}
void main( )
{
double distance;
CPoint p1,p2,p;
cout<<"第1个点p1,";
p1.input();
cout<<"第2个点p2,";
p2.input();
distance=p1.Distance(p2);
cout<<"两点之间的距离为:"<<distance<<endl;
distance=p1.Distance0();
cout<<"p1到原点的距离为:"<<distance<<endl;
p=p1.SymmetricAxis(axisx);
cout<<"p1关于x轴的对称点为:";
p.output();
p=p1.SymmetricAxis(axisy);
cout<<"p1关于y轴的对称点为:";
p.output();
p=p1.SymmetricAxis(point);
cout<<"p1关于原点的对称点为:";
p.output();
system("pause");
}
- 第六周实验报告
- 第六周实验一
- 第六周实验二
- 第六周实验三
- 第六周实验
- 第六周C++实验报告
- C++第六周实验报告
- 第六周实验报告1
- 第六周实验报告1
- 第六周实验报告1
- 第六周实验任务一
- 第六周实验报告1
- 第六周实验报告1
- 第六周实验报告1
- 第六周实验报告2
- 第六周实验报告二
- 第六周实验报告2
- 第六周实验报告3
- 凯撒加密与矩阵换位加密
- jquery accordion 手风琴的使用
- Xcode 有用
- php安装http扩展(sudo apt-get install)
- 位序转字符串的一种高效方法
- 第六周实验
- C# 中的委托和事件
- m_Time = CTime::GetCurrentTime();
- SVN上拖下来的项目,缺少build path怎么办?
- c++程序设计实验报告6-4
- C#中的委托和事件(续)
- Myeclipse常用快捷键
- 人力资源excel导入
- SNMP的学习笔记