C++:继承3(是圆内、圆外还是圆上)
来源:互联网 发布:淘宝接单app软件 编辑:程序博客网 时间:2024/06/06 01:34
继承3(是圆内、圆外还是圆上)
Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByte
Total Submit:272 Accepted:200
Description
定义点类为基类,其数据成员x和y为私有成员。再定义圆类继承点类,该点为圆的圆心,新增数据成员圆的半径。
在圆类中定义成员函数,其形式参数为一个点,判断该点是在圆内部、圆外还是圆上。
Input
包含多组测试例, 每组数据的第1行是圆心的坐标,第2行是圆的半径,第1行是另外一个点的坐标。
Output
如果点在圆内部输出“in”,点在圆外输出“out”,点在在圆上输出“on”。
Sample Input
0 0
8
6 8
0 0
10
6 8
0 0
12
6 8
Sample Output
out
on
in
Hint
不要使用sqrt函数,通过比较距离的平方与半径的平方来避免误差。
#include<iostream>using namespace std;class Point{protected: int x,y;public: Point(int a,int b) { x=a; y=b; }};class Circle:public Point{ int x1,y1,r;public: Circle(int a,int b,int c,int d,int e):Point(a,b) { x1=d; y1=e; r=c; } void disp() { double s,s1,m; s=(x-x1)*(x-x1)+(y-y1)*(y-y1); s1=r*r; m=s-s1; if(m>0) cout<<"out"<<endl; else { if(m==0) cout<<"on"<<endl; else cout<<"in"<<endl;} } };int main(){ int a,b,c,d,e; while(cin>>a>>b>>c>>d>>e) { Circle w(a,b,c,d,e);w.disp(); } return 0;}
1 0
- C++:继承3(是圆内、圆外还是圆上)
- C++】多重继承,救世主还是鸡肋
- C++:在堆上创建对象,还是在栈上?
- fork - 继承还是不继承
- 国学:继承还是放弃
- 使用继承?还是接口...
- 使用继承还是组合...
- 继承还是代理啊?????
- 还是继承那些实例---
- 继承还是委托?
- 组合还是继承
- ex44 继承还是组成
- 还是C
- 在WEB上发展,还是在C#,或者C++/C,还或者Linux???
- 面向对象:接口继承还是类继承?
- C++,类的对象,其地址,栈上还是堆上?
- [翻译] Effective C++, 3rd Edition, Item 34: 区分 inheritance of interface(接口继承)和 inheritance of implementation(实现继承)(上)
- 还是那些继承实例二
- css中中float,relative,absolute的使用注意的问题
- leetCode 104. Maximum Depth of Binary Tree
- 我收藏的有关Python的电子书和资料
- android ValueAnimator ObjectAnimator
- LeetCode Sort Colors
- C++:继承3(是圆内、圆外还是圆上)
- 从工程中删除Cocoapods
- Android Java四种引用区分 <17>
- 前后端分离,ajax前端跨域访问后端
- 收集的一些比较好的博客
- android开发之Camera(相机)
- 一篇关于字节序的文章
- hdu 3966 树链剖分(坑内存)
- java基础学习