第十二周任务4(不完整)

/* (程序头部注释开始) 
* 程序的版权和版本声明部分 
* Copyright (c) 2011, 烟台大学计算机学院学生  
* All rights reserved. 
* 文件名称:                               
* 作    者:  杨建和                
* 完成日期:   2012   年 5  月 7 日 
* 版 本 号:           
 
* 对任务及求解方法的描述部分 
* 输入描述:类的组合与继承(1)先建立一个Point(点)类,包含数据成员x,y(坐标点);(2)以Point为基类,派生出一个Circle(圆)类,增加数据成员(半径),基类的成员表示圆心;(3)编写上述两类中的构造、析构函数及必要的输入输出函数(4)定义友元函数int locate,判断点p在圆c上、圆c内或圆c外,返回值<0圆内,==0圆上,>0 圆外;(5)重载关系运算符(6种)运算符,使之能够按圆的面积比较两个圆的大小;(6)给定一点p,求出该点与圆心相连成的直线与圆的两个交点并输出
* 问题描述:* 程序头部的注释结束 

*/ 

#include <iostream>  
 
#include <cmath>  
  
using namespace std;  
  
#define PI 3.1415926  
//自行定义类  
class Point //定义坐标点类  
{   
public:  
    double x, y;//点的横坐标和纵坐标  
    Point(){x = 0; y = 0;}  
    ~Point(){}  
    Point(double x0, double y0) {x = x0; y = y0;}  
    double getX(){return x;}  
    double getY(){return y;}  
    friend ostream& operator << (ostream&, Point&);  
    friend istream& operator >> (istream&, Point&);  
};  
ostream& operator << (ostream& output, Point& p)  
{  
    output << "(" << p.x << "," << p.y << ")" << endl;  
  
    return output;  
}  
istream& operator >> (istream& input, Point& p)   
{  
    cout << "输入点的横纵坐标:(x y)";  
    input >> p.x >> p.y;  
  
    return input;  
}  
class Circle : public Point  
{  
protected:  
    double r;  
public:  
    Circle(){}  
    Circle(double x, double y, double r = 0):Point(x, y){r = r;}  
    ~Circle(){}    
    double getR(){return r;}  
    double getAre(){return PI*r*r/2;}  
    friend ostream& operator << (ostream&, Circle&);  
    friend istream& operator >> (istream&, Circle&);  
    friend double locate(Point p, Circle c);  
    bool operator > (Circle &c);  
    bool operator < (Circle &c);  
    bool operator >= (Circle &c);  
    bool operator <= (Circle &c);  
    bool operator == (Circle &c);  
    bool operator != (Circle &c);  
  //  void crossover_point1(Point p, Circle c, Point &p1, Point &p2);  
};  

bool Circle::operator > (Circle &c)  
{  
    if (getAre() > c.getAre())  
        return true;  
    else  
        return false;  
}  
bool Circle::operator < (Circle &c)  
{  
    if (getAre() < c.getAre())  
        return true;  
    else  
        return false;  
}  
bool Circle::operator >= (Circle &c)  
{  
    if (getAre() >= c.getAre())  
        return true;  
    else  
        return false;  
}  
bool Circle::operator <= (Circle &c)  
{  
    if (getAre() <= c.getAre())  
        return true;  
    else  
        return false;  
}  
bool Circle::operator == (Circle &c)  
{  
    if (getAre() == c.getAre())  
        return true;  
    else  
        return false;  
}  
bool Circle::operator != (Circle &c)  
{  
    if (getAre() != c.getAre())  
        return true;  
    else  
        return false;  
}  
double locate(Point p, Circle c)  
{  
    return (sqrt((c.x - p.x)*(c.x - p.x) + (c.y - p.y)*(c.y - p.y)) - c.r);  
}  
ostream& operator << (ostream& out, Circle& c)  
{  
    out << "圆心:" << "(" << c.x << "," << c.y << ")" << endl;  
    out << "半径:" << c.r << endl;  
  
    return out;  
}  
istream& operator >> (istream& in, Circle& c)  
{  
    cout << "输入圆心坐标:(x y)";  
    in >> c.x >> c.y;  
    cout << "请输入圆的半径:(r)" ;  
    in >> c.r;  
  
    return in;  
}  


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;
}

总结:求 给定一点p,求出该点与圆心相连成的直线与圆的两个交点并输出  的函数还没有写出来。。。感觉有点难

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值