主题:菜鸟求助c++类
class point
{
public:
void setxy(double _x,double _y);
double dist(point &p);
double getx();
double gety();
private:
double x,y;
};
#include"point.h"
#include"math.h"
void point::setxy(double _x,double _y)
{
x=_x;
y=_y;
}
double point::getx()
{
return x;
}
double point::gety()
{
return y;
}
double point::dist(point &p)
{
return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
class circle
{
public:
void setcircle(point &c,double &r);
bool isincircle(point &p);
point getc();
double getr();
private:
point center;
double radius;
};
#include"point.h"
#include"circle.h"
void circle::setcircle(point &c,double &r)
{
center=c;
radius=r;
}
point circle::getc()
{
return center;
}
double circle::getr()
{
return radius;
}
bool circle::isincircle(point &p)
{
double d;
d=center.dist(p);
if(d>radius)
return false;
else
return true;
}
#include"point.h"
#include"circle.h"
#include<iostream>
using namespace std;
void main()
{
circle c;
point center,p;
double x,y,r;
cin>>x>>y>>r;
center.setxy(x,y);
c.setcircle(center,r);
cin>>x>>y;
p.setxy (x,y);
if(d==r+p.r)
cout>>"1";
else if(d>r+p.r)
cout>>"2";
else if(d=r-p.r)
cout>>"3";
else
cout>>"4";
}
如果两个圆相切输出1,两个圆相离输出2、两个圆包含输出3、两个圆相交输出4。
这是我写的求两圆位置关系的代码,好像还有很多错误,是未定义什么的,但是我不是定义过的??求助,实验报告马上就要交了。
{
public:
void setxy(double _x,double _y);
double dist(point &p);
double getx();
double gety();
private:
double x,y;
};
#include"point.h"
#include"math.h"
void point::setxy(double _x,double _y)
{
x=_x;
y=_y;
}
double point::getx()
{
return x;
}
double point::gety()
{
return y;
}
double point::dist(point &p)
{
return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
class circle
{
public:
void setcircle(point &c,double &r);
bool isincircle(point &p);
point getc();
double getr();
private:
point center;
double radius;
};
#include"point.h"
#include"circle.h"
void circle::setcircle(point &c,double &r)
{
center=c;
radius=r;
}
point circle::getc()
{
return center;
}
double circle::getr()
{
return radius;
}
bool circle::isincircle(point &p)
{
double d;
d=center.dist(p);
if(d>radius)
return false;
else
return true;
}
#include"point.h"
#include"circle.h"
#include<iostream>
using namespace std;
void main()
{
circle c;
point center,p;
double x,y,r;
cin>>x>>y>>r;
center.setxy(x,y);
c.setcircle(center,r);
cin>>x>>y;
p.setxy (x,y);
if(d==r+p.r)
cout>>"1";
else if(d>r+p.r)
cout>>"2";
else if(d=r-p.r)
cout>>"3";
else
cout>>"4";
}
如果两个圆相切输出1,两个圆相离输出2、两个圆包含输出3、两个圆相交输出4。
这是我写的求两圆位置关系的代码,好像还有很多错误,是未定义什么的,但是我不是定义过的??求助,实验报告马上就要交了。