上机内容:C++程序的编写和运行
上机目的:掌握简单C++程序的编辑、编译、连接和运行的一般过程
我的程序:
运行结果:
心得体会: 上周落下的,今晚上赶快做出来吧,要不明天上机课,会有压力啊。。。
知识点总结:略
上机目的:掌握简单C++程序的编辑、编译、连接和运行的一般过程
我的程序:
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 作 者:赵玲玲
* 完成日期:2014 年 3 月 10 日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:点结构体与枚举
* 程序输出:略
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
#include<cmath>
using namespace std;
enum SymmetricStyle {axisx,axisy,point};//分别表示按x轴, y轴, 原点对称
struct Point
{
double x; // 横坐标
double y; // 纵坐标
};
double Distance(Point p1, Point p2); // 两点之间的距离
double Distance0(Point p1);
int main( )
{
Point p1= {1,5},p2= {4,1},p;
Point symmetricAxis(Point p,SymmetricStyle style); //返回对称点
cout<<"两点的距离为:"<<Distance(p1,p2)<<endl;
cout<<"p1到原点的距离为:"<<Distance0(p1)<<endl;
p=symmetricAxis(p1,axisx);
cout<<"p1关于x轴的对称点为:"<<"("<<p.x<<", "<<p.y<<")"<<endl;
p=symmetricAxis(p1,axisy);
cout<<"p1关于y轴的对称点为:"<<"("<<p.x<<", "<<p.y<<")"<<endl;
p=symmetricAxis(p1,point);
cout<<"p1关于原点的对称点为:"<<"("<<p.x<<", "<<p.y<<")"<<endl;
return 0;
}
// 求两点之间的距离
double Distance(Point p1,Point p2)
{
double d;
int d1=0,d2=0,d3=0;
if(p1.x<p2.x)
{
d1=p2.x-p1.x;
}
else
{
d1=p1.x-p2.x;
}
if(p2.y<p1.y)
{
d2=p1.y-p2.y;
}
else
{
d2=p2.y-p1.y;
}
d3=d1*d1+d2*d2;
d=sqrt(d3);
return d;
}
// 求点到原点的距离
double Distance0(Point p)
{
double d;
int d1=0;
d1=p.x*p.x+p.y*p.y;
d=sqrt(d1);
return d;
}
// 求对称点
Point symmetricAxis(Point p1,SymmetricStyle style)
{
switch(style)
{
case axisx:
p1.x=-p1.x;
return p1;
case axisy:
p1.y=-p1.y;
return p1;
case point:
p1.x=-p1.x;
p1.y=-p1.y;
return p1;
default:
cout<<"error"<<endl;
}
return p1;
}
运行结果:
心得体会: 上周落下的,今晚上赶快做出来吧,要不明天上机课,会有压力啊。。。
知识点总结:略