修改好了,问题都已经在程序里响应位置标出了:
#include
#include
using namespace std;
class point
{
public: //根据你程序,这儿需要用public,protected和private再类外都是无法访问的
int x,y;
public:
point(){}; //加上默认构造函数
point(int a,int b):x(a),y(b){} //不是piont,拼写错误
};
class circle:public point
{
public://根据你程序,这儿需要用public protected和private再类外都是无法访问的
int radius;
public:
circle(){};//加上默认构造函数
circle(int a,int b,int c=0):point(a,b),radius(c){}
circle(circle&c2); //缺少了
float distance(circle&c2);
};
circle::circle(circle&c2) //拷贝构造函数
{
x=c2.x;
y=c2.y;
radius=c2.radius;
}
float circle::distance(circle&c2)
{
float x1 = x;
float y1 = y;
float x2 = c2.x;
float y2 = c2.y;
return(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
int main()
{
circle c1(0,0,4),c2(5,5),c4(3,3);
circle c3=c1;
float dis;
dis=c1.distance(c2);
if(dis>4)
cout<<"c2 is outside of c1\n";
dis=c3.distance(c4);
if(dis>4)
cout<<"c4 is outside of c3\n";
return 0;
}