第十二周上机任务4
来源:互联网 发布:java string得到其中 编辑:程序博客网 时间:2024/04/29 19:52
/* (程序头部注释开始)* 程序的版权和版本声明部分* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称:renwu.cpp * 作 者:宋本一 * 完成日期:2012 年 5 月 6 日* 版 本 号:12.3 * 对任务及求解方法的描述部分* 输入描述:略 * 问题描述:略 * 程序输出:略* 程序头部的注释结束*/#include<iostream> #include<Cmath> using namespace std; const double pi=3.1415926; class Point //定义坐标点类 { public: Point(){x=0;y=0;} Point(double x0,double y0) {x=x0; y=y0;} ~Point () { cout<<"Point类析构函数执行完毕(Destructor function performs finished)"<<endl; } double get_x(){return x;} double get_y(){return y;} void set_x(double n){ x=n;} void set_y(double n){y=n;} friend ostream &operator << (ostream & output, Point & c); private: double x,y; //点的横坐标和纵坐标 }; ostream &operator << (ostream & output, Point & c) { output<<"该点的横坐标为:"<<c.x<<" "<<"纵坐标为:"<<c.y<<endl; return output; } class Circle: public Point //利用坐标点类定义圆类, 其基类的数据成员表示圆的中心 { public: Circle(double xx,double yy,double dd): Point(xx,yy) ,d(dd){}//构造函数 ~Circle() { cout<<"Circle类析构函数执行完毕(Destructor function performs finished)"<<endl; } friend ostream &operator << (ostream & output, Circle & c); friend double locate(Point &,Circle &); friend void crossover_point1(Point &p1,Circle &c1,Point &p4,Point &p5); bool operator > (Circle &t); bool operator < (Circle &t); bool operator >= (Circle &t); bool operator <= (Circle &t); bool operator == (Circle &t); bool operator != (Circle &t); private: double d; }; void crossover_point1(Point &p1,Circle &c1,Point &p4,Point &p5) { double n; n=c1.get_x ()+((p1.get_x ()-c1.get_x ())*c1.d )/(sqrt((p1.get_x ()-c1.get_x ())*(p1.get_x ()-c1.get_x ())+((p1.get_y ()-c1.get_y ())*(p1.get_y ()-c1.get_y ())))); p4.set_x (n); n=c1.get_x ()-((p1.get_x ()-c1.get_x ())*c1.d )/(sqrt((p1.get_x ()-c1.get_x ())*(p1.get_x ()-c1.get_x ())+((p1.get_y ()-c1.get_y ())*(p1.get_y ()-c1.get_y ())))); p5.set_x (n); n=c1.get_y ()+((p1.get_y ()-c1.get_y ())*c1.d )/(sqrt((p1.get_x ()-c1.get_x ())*(p1.get_x ()-c1.get_x ())+((p1.get_y ()-c1.get_y ())*(p1.get_y ()-c1.get_y ())))); p4.set_y (n); n=c1.get_y ()-((p1.get_y ()-c1.get_y ())*c1.d )/(sqrt((p1.get_x ()-c1.get_x ())*(p1.get_x ()-c1.get_x ())+((p1.get_y ()-c1.get_y ())*(p1.get_y ()-c1.get_y ())))); p5.set_y (n); } ostream &operator << (ostream & output, Circle & c) { output<<"圆的半径为:"<<c.d<<"圆的圆心为"<<"("<<c.get_x()<<","<<c.get_y()<<")"<<endl; return output; } double locate(Point &p,Circle &c) { double s,d,m; s=(c.get_x()-p.get_x () )*(c.get_x()-p.get_x () )+(c.get_y ()-p.get_y () )*(c.get_y ()-p.get_y () ); m=sqrt(s); d=m-c.d ; return d; } bool Circle::operator > (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if(s1>s2 ) return true; else return false; } bool Circle::operator < (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if(s1<s2 ) return true; else return false; } bool Circle::operator >= (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if (s1<s2) return false; return true; } bool Circle::operator <= (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if (s1>s2) return false; return true; } bool Circle::operator == (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if (s1<s2) return false; if (s1>s2) return false; return false; } bool Circle::operator != (Circle &t) { double s1,s2; s1=pi*d*d; s2=pi*t.d*t.d; if (s1==s2) return false; return true; } int main( ) { Circle c1(3,2,4),c2(4,5,5); //c2应该大于c1 Point 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; cout<<endl; cout<<"圆c1: "<<c1; if(c1>c2) cout<<"大于"<<endl; if(c1<c2) cout<<"小于"<<endl; if(c1>=c2) cout<<"大于等于"<<endl; if(c1<=c2) cout<<"小于等于"<<endl; if(c1==c2) cout<<"等于"<<endl; if(c1!=c2) cout<<"不等于"<<endl; cout<<"圆c2: "<<c1; cout<<endl; Point p4,p5; crossover_point1(p1,c1, p4, p5); cout<<"点p1: "<<p1; cout<<"与圆c1: "<<c1; cout<<"的圆心相连,与圆交于两点,分别是:"<<endl; cout<<"交点: "<<p4; cout<<"交点: "<<p5; cout<<endl; system("PAUSE"); return 0; }
运行结果:
圆c1: 圆的半径为:4圆的圆心为(3,2)
点p1: 该点的横坐标为:1 纵坐标为:1
点p1在圆c1之内
点p2: 该点的横坐标为:3 纵坐标为:-2
点p2在圆c1之上
点p3: 该点的横坐标为:7 纵坐标为:3
点p3在圆c1之外
圆c1: 圆的半径为:4圆的圆心为(3,2)
小于
小于等于
不等于
圆c2: 圆的半径为:4圆的圆心为(3,2)
点p1: 该点的横坐标为:1 纵坐标为:1
与圆c1: 圆的半径为:4圆的圆心为(3,2)
的圆心相连,与圆交于两点,分别是:
交点: 该点的横坐标为:-0.577709 纵坐标为:0.211146
交点: 该点的横坐标为:6.57771 纵坐标为:3.78885
请按任意键继续. . .
- 第十二周上机任务4
- 第十二周上机任务1
- 第十二周上机任务2
- 第十二周上机任务3
- 第十二周上机任务1
- 第十二周上机任务2
- 第十二周上机任务1
- 第十二周上机任务2
- 第十二周上机任务1
- 第十二周上机任务2
- C++ 第十二周上机任务-输出“#”
- java上机 第十二周 任务一
- 第十二周上机任务==素数
- 第十二周上机任务项目-4输出10000以内的素数任务1
- 第十二周上机任务项目-4输出10000以内的回文数任务2
- 第十二周上机任务项目-4输出10000以内回文素数任务3
- 调用函数求特殊三位数(第十二周上机任务)
- 第十二周上机项目一任务二--输出星号图
- sql server2000分页语句
- VC 写 TXT 文件分割器 附代码
- Android Uevent 分析,从kernel到framework
- File类中常用方法!
- windows batch启动java应用(设置classpath)
- 第十二周上机任务4
- freebsd 配置 SMTP
- Linux下C抓取网页
- 2010.10.30_ximo_过VMP的vmware的检测
- Dennis Ritchie逝世, 享年70岁
- Python、Django以及PyCharm安装心得
- A beginner's guide to writing a custom stream buffer (std::streambuf)
- HashMap和Hashtable 之源代码详解
- 2010.11.03_ximo_过VMP加壳程序的自效验(vmp 2.06)