第12周项目4-圆与点的关系
来源:互联网 发布:成都正规java培训机构 编辑:程序博客网 时间:2024/05/01 02:54
#include <iostream>#include <cmath>using namespace std;class Point{public:Point() :x(0), y(0){};Point(int xx, int yy) :x(xx), y(yy){};friend ostream &operator<<(ostream &out, const Point &a);int x;int y;};ostream &operator<<(ostream &out, const Point &a){out << "Point=[" << a.x << ", " << a.y << "]" << endl;return out;}class Circle:public Point{public:Circle(int xx, int yy, int rr) :Point(xx,yy), r(rr){};friend ostream &operator<<(ostream &out, Circle &a);friend int locate(Point &p, Circle &c);int r;};int locate(Point &p, Circle &c){double l,m;l = sqrt((p.x - c.x)*(p.x - c.x) + (p.y - c.y)*(p.y - c.y));m=l - c.r;if(m>0) return 11; if(m<0) return -11; if(m==0) return 0;}ostream &operator<<(ostream &out, Circle &a){out << "Center=[" << a.x << ", " << a.y << "], r=" << a.r << endl;return out;}int main(){Circle c1(3, 2, 4), c2(4, 5, 5); //c2应该大于c1Point 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
- 第12周项目4-圆与点的关系
- 第12周项目4—点、圆的关系
- 第12周项目4-点、圆的关系
- 第12周项目-4、点、圆的关系
- 第12周项目4-点、圆的关系
- 第12周项目4 - 点、圆的关系
- 第12周 项目4 点、圆的关系
- 第11周-项目4-点、圆的关系-判断点p与圆的位置关系
- 第11周项目4-1点圆的关系
- 第12周 项目四-点、圆关系(4)
- 第12周 【项目4 - 点、圆的关系】(1)
- 第12周 【项目4 - 点、圆的关系】(2)
- 第12周 【项目4 - 点、圆的关系】(3)
- 第12周项目4-点、圆的关系(1)
- 第12周项目4-点、圆的关系(2)
- 第12周项目4-点和圆的关系(2)
- 第12周项目4-点和圆的关系(3)
- 第12周上机实践项目4——点、圆的关系(2)
- VMware Tools在linux下的安装方法
- getLocationInWindow和getLocationOnScreen的区别
- Windows文件类型
- 无废话WCF入门教程二[WCF应用的通信过程]
- Spring 事务机制详解
- 第12周项目4-圆与点的关系
- javascript基础
- 无废话WCF入门教程三[WCF的宿主]
- 队列(三):链式存储队列
- myBatis的SQL注入问题
- 无废话WCF入门教程四[WCF的配置文件]
- C语言高级语法概述笔记
- Css浮动
- 无废话WCF入门教程五[WCF的通信模式]