#include<iostream>
/* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 李瑞
* 完成日期: 2012 年5 月9 日
* 版 本 号: v1.0
* 对任务及求解方法的描述部分
* 输入描述:……
* 问题描述:……
* 程序输出:……
* 程序头部的注释结束*/
#include<Cmath>
#include<iomanip>
using namespace std;
class Point
{
public:
Point(){x = 0; y = 0;}
Point(double x0,double y0) {x = x0; y = y0;}
~Point(){}
double getx(){return x;}
double gety(){return y;}
friend ostream & operator << (ostream &, Point &);
double x, y;
};
class Circle: public Point
{
public:
Circle(){radii = 0;}
Circle(double x0, double y0, double r);
~Circle(){};
friend int locate(Point p1, Circle c1);
double Length(Point p1, Point p2);
friend ostream & operator << (ostream &, Circle &);
friend bool operator > (Circle & c1, Circle & c2);
friend bool operator < (Circle & c1, Circle & c2);
friend bool operator >= (Circle & c1, Circle & c2);
friend bool operator <= (Circle & c1, Circle & c2);
friend bool operator == (Circle & c1, Circle & c2);
friend bool operator != (Circle & c1, Circle & c2);
friend void crossover_point1(Point & p1, Circle & c1, Point & p4, Point & p5);
protected:
double radii;
};
Circle::Circle(double x0, double y0, double r):Point(x0, y0),radii(r){}
void crossover_point1(Point & p1, Circle & c1, Point & p4, Point & p5)
{
double x0 = (c1.x - p1.x) * c1.radii / sqrt((c1.x - p1.x) * (c1.x - p1.x) + (c1.y - p1.y) * (c1.y - p1.y));
double y0 = (c1.y - p1.y) * c1.radii / sqrt((c1.x - p1.x) * (c1.x - p1.x) + (c1.y - p1.y) * (c1.y - p1.y));
p4.x = c1.x + x0;
p4.y = c1.y + y0;
p5.x = c1.x - x0;
p5.y = c1.y - y0;
}
int locate(Point p1, Circle c1)
{
double length = sqrt((p1.x - c1.x) * (p1.x - c1.x) + (p1.y - c1.y) * (p1.y - c1.y));
if(length < c1.radii)
{
return 1;
}
else if(length == c1.radii)
{
return 0;
}
else
{
return -1;
}
}
ostream & operator << (ostream & out, Point & p)
{
out << "(" << p.x << "," << p.y << ")" << endl;
return out;
}
ostream & operator << (ostream & out, Circle & c)
{
out << "以" << "(" << c.x << "," << c.y << ")为圆心," << "半径为 " << c.radii << "的圆 " << endl;
return out;
}
bool operator > (Circle & c1, Circle & c2)
{
if(c1.radii > c2.radii)
{
return true;
}
else
{
return false;
}
}
bool operator < (Circle & c1, Circle & c2)
{
if(c1.radii < c2.radii)
{
return true;
}
else
{
return false;
}
}
bool operator >= (Circle & c1, Circle & c2)
{
if(c1.radii >= c2.radii)
{
return true;
}
else
{
return false;
}
}
bool operator <= (Circle & c1, Circle & c2)
{
if(c1.radii <= c2.radii)
{
return true;
}
else
{
return false;
}
}
bool operator == (Circle & c1, Circle & c2)
{
if(c1.radii == c2.radii)
{
return true;
}
else
{
return false;
}
}
bool operator != (Circle & c1, Circle & c2)
{
if(c1.radii != c2.radii)
{
return true;
}
else
{
return false;
}
}
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: " << c2;
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;
}