结构体和枚举处理点的问题

来源:互联网 发布:c语言复合语句的用法 编辑:程序博客网 时间:2024/05/02 00:02
*烟台大学计算机学院学生                                                                     *All rights reserved.                                                    *文件名称:结构体和枚举处理点的问题       *作者:杨飞                                                                              *完成日期:2013年3月8日                                                                   *版本号: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);Point symmetricAxis(Point p1,SymmetricStyle style);   //返回对称点int main( ){    Point p1={1,5},p2={4,1},n;    cout<<"两点的距离为:"<<distance(p1,p2)<<endl;    cout<<"p1到原点的距离为:"<<distance0(p1)<<endl;    n=symmetricAxis(p1,axisx);    cout<<"p1关于x轴的对称点为:"<<"("<<n.x<<", "<<n.y<<")"<<endl;    n=symmetricAxis(p1,axisy);    cout<<"p1关于y轴的对称点为:"<<"("<<n.x<<", "<<n.y<<")"<<endl;    n=symmetricAxis(p1,point);    cout<<"p1关于原点的对称点为:"<<"("<<n.x<<", "<<n.y<<")"<<endl;    return 0;}// 求两点之间的距离double distance(Point p1,Point p2){    double d,d1;    d1=pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2);d=sqrt(d1);    return d;}// 求点到原点的距离double distance0(Point p){    double d;    d=sqrt(pow(p.x,2)+pow(p.y,2));    return d;}// 求对称点Point symmetricAxis(Point p1,SymmetricStyle style){    Point n;    if(style==axisx)    {        n.x=p1.x;        n.y=-p1.y;    }    else if(style==axisy)    {        n.x=-p1.x;        n.y=p1.y;    }    else    {        n.x=-p1.x;        n.y=-p1.y;    }    return n;}

运行结果:

心得体会:费了好大劲,12.11版codeblock不能运行,在vc++上能运行出来,怎么回事?是编译系统的事?

0 0
原创粉丝点击