1000. Circle and Rectangle

#include<iostream>
#include<cmath>
using namespace std;

class Point{

private:

 double x,y;

public:

 Point();

 Point(double xv,double yv);

 Point(Point& pt);

 double getx();

 double gety();

};

Point::Point(){
 x=0;y=0;
}

Point::Point(double xv,double yv){
 x=xv;y=yv;
}

Point::Point(Point& pt){
 this->x = pt.x;
 this->y = pt.y;
}

double Point::getx(){
 return x;
}
double Point::gety(){
 return y;
}


class Circle : public Point{
 public:
  Circle(double x,double y,double r);
  Circle();
  Circle(Circle &);
     int position(Point &pr){
      double a = pow(pr.getx() - this->getx(),2) + pow(pr.gety() - this->gety(),2);
      if(a==r*r) return 0;
      if(a>r*r) return 1;
      if(a<r*r) return -1;
      }
    private:
     double r;
};

Circle::Circle(double x,double y,double r) : Point(x,y){
 this->r=r;
}

Circle::Circle() : Point(){
 r=0;
}

Circle::Circle(Circle &t) : Point(t.getx(),t.gety()){
 r = t.r;
}

class Rectangle : public Point{
 public:
  
     Rectangle(double x,double y,double len,double wid) : Point(x,y){
      this->len=len;
      this->wid=wid;
     }
     Rectangle();
  Rectangle(Rectangle &);
     int position(Point &pr){
      double a = pr.getx() - this->getx();
      double b = pr.gety() - this->gety();
//      cout<<a<<"KKKK"<<b<<endl;
//      if((a==0&&b<=wid&&b>0)||(a>0&&a<=len&&b==0)||(a==len&&b<=wid&&b>0)||(a>0&&a<=len&&b==wid)) return 0;
      if(a<len&&a>0&&b<wid&&b>0) return -1;
      else if(a>len||b>wid||a<0||b<0) return 1; //wai
      else return 0; //zai
      }
    private:
     double len;
     double wid;
};

Rectangle::Rectangle() : Point(){
 len=1;
 wid=1;
}
Rectangle::Rectangle(Rectangle &t): Point(t.getx(),t.gety()){
 len = t.len;
 wid = t.wid;
}

 

转载于:https://www.cnblogs.com/sysu-eeman-yang/p/5987377.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值