点、圆的关系

来源:互联网 发布:剑倚天下宝器进阶数据 编辑:程序博客网 时间:2024/05/22 00:08
/** 程序的版权和版本声明部分:* Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 文件名称:test.cpp* 作    者:任子仪* 完成日期:2014年 5月 20日* 版 本 号:v12.1* 输入描述:无* 问题描述:。* 程序输出:* 问题分析:略* 算法设计:略*/#include <iostream>using namespace std;class CPoint{public:    CPoint():x(0),y(0) {};    CPoint(double x0, double y0):x(x0), y(y0) {};  double get_x()    {        return x;    }    double get_y()    {        return y;    }     friend ostream& operator << (ostream &output,CPoint&c)     {         output<<"("<<c.x<<","<<c.y<<")"<<endl;         return output;     }protected:    double x;    double y;};class Circle:public CPoint{private:    double r;public:    Circle(double xx,double yy,double r1):CPoint(xx,yy),r(r1) {};    friend double locate(CPoint &c2,Circle c1)    {        double z;        double x2=c2.get_x();        double y2=c2.get_y();        z=(c1.x-x2)*(c1.x-x2)+(c1.y-y2)*(c1.y-y2)-c1.r*c1.r;        return z;    }};int main( ){    Circle c1(3,2,4),c2(4,5,5);      //c2应该大于c1    CPoint p1(1,1),p2(3,-2),p3(7,3);  //分别位于c1内、上、外    cout<<"圆c1: "<<c1;    cout<<"点p1: "<<p1;    cout<<"点p1在圆c1之"<<((locate(p1, c1)>0)?"外":((locate(p1, c1)<0)?"内":"上"))<<endl;    cout<<"点p2: "<<p2;    cout<<"点p2在圆c1之"<<((locate(p2, c1)>0)?"外":((locate(p2, c1)<0)?"内":"上"))<<endl;    cout<<"点p3: "<<p3;    cout<<"点p3在圆c1之"<<((locate(p3, c1)>0)?"外":((locate(p3, c1)<0)?"内":"上"))<<endl;    return 0;}

示例图片:


心得体会:今天五月二十号,注定要与程序作伴啊,啥也不说了。。。。。。。。。。。

0 0
原创粉丝点击