下面代码在VC中执行报出一个错误,我没找到请高手指点
#include<iostream.h>classCCircle;structCPoint{unsignedx;unsignedy;boolIsInCircle(CCir...
#include<iostream.h>
class CCircle;
struct CPoint
{
unsigned x;
unsigned y;
bool IsInCircle(CCircle*Circle);
};
class CCircle
{
public;
unsigned Radius;
CPoint Center;
};
bool CPiont::IsInCircle(CCircle*Circle)//这段代码定义不是理解请高手详细解释下
{
return (((x-Circle->Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
<=Circle->Radius*Circle->Radius
);
};
void main()
{
CPoint Center;
CPoint Point;
CCircle Circle;
Center x=0
CPiont Point;
CCircle Circle;
Center.x=0;
Center.y=0;
Point.x=2;
Point.y=3;
Circle.Radius=3;
Circle.Center=Center;
if(Point.IsInCircle(&Circle))
cout<<"The point is in the circle."<<endl;
else
cout<<"The point is not in the circle."<<endl;
} 展开
class CCircle;
struct CPoint
{
unsigned x;
unsigned y;
bool IsInCircle(CCircle*Circle);
};
class CCircle
{
public;
unsigned Radius;
CPoint Center;
};
bool CPiont::IsInCircle(CCircle*Circle)//这段代码定义不是理解请高手详细解释下
{
return (((x-Circle->Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
<=Circle->Radius*Circle->Radius
);
};
void main()
{
CPoint Center;
CPoint Point;
CCircle Circle;
Center x=0
CPiont Point;
CCircle Circle;
Center.x=0;
Center.y=0;
Point.x=2;
Point.y=3;
Circle.Radius=3;
Circle.Center=Center;
if(Point.IsInCircle(&Circle))
cout<<"The point is in the circle."<<endl;
else
cout<<"The point is not in the circle."<<endl;
} 展开
5个回答
展开全部
#include<iostream.h>
class CCircle;
class CPoint
{
public:
unsigned x;
unsigned y;
bool IsInCircle(CCircle*Circle);
};
class CCircle
{
public:
unsigned Radius;
CPoint Center;
};
bool CPoint::IsInCircle(CCircle*Circle)
{
return (((x-Circle->Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
<=Circle->Radius*Circle->Radius
);
};
void main()
{
CPoint Center;
CPoint Point;
CCircle Circle;
Center.x=0;
Center.y=0;
Point.x=2;
Point.y=3;
Circle.Radius=3;
Circle.Center=Center;
if(Point.IsInCircle(&Circle))
cout<<"The point is in the circle."<<endl;
else
cout<<"The point is not in the circle."<<endl;
}
帮你把代码改好了,能够运行了,平时注意的你拼写问题~~~有什么不明白的,可以继续追问~~
class CCircle;
class CPoint
{
public:
unsigned x;
unsigned y;
bool IsInCircle(CCircle*Circle);
};
class CCircle
{
public:
unsigned Radius;
CPoint Center;
};
bool CPoint::IsInCircle(CCircle*Circle)
{
return (((x-Circle->Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
<=Circle->Radius*Circle->Radius
);
};
void main()
{
CPoint Center;
CPoint Point;
CCircle Circle;
Center.x=0;
Center.y=0;
Point.x=2;
Point.y=3;
Circle.Radius=3;
Circle.Center=Center;
if(Point.IsInCircle(&Circle))
cout<<"The point is in the circle."<<endl;
else
cout<<"The point is not in the circle."<<endl;
}
帮你把代码改好了,能够运行了,平时注意的你拼写问题~~~有什么不明白的,可以继续追问~~
追问
我这段代码中主要那里出错了,你改了哪里,还有这段:
bool CPoint::IsInCircle(CCircle*Circle)
{
return (((x-Circle->Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
Radius*Circle->Radius
);
};
麻烦你给详细解释下代码的每句的意思和作用谢谢
追答
知道怎么判断一个坐标点是否在一个圆内么?
x^2+y^2Center.x)*(x-Circle->Center.x)
+(y-Circle->Center.y)*(y-Circle->Center.y)
)
Radius*Circle->Radius
);
成立,则说明点在圆内……就这么简单而已,这只有一句话……
至于说,我改了哪些地方,自己对照着看看不就懂了?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
IsInCircle函数在计算那个点是否在圆内,x的平方加上y的平方,如果大于半径的平方就在圆外返回0,如果小于就返回1
错误应该出现在下面几句里;
CPoint Center;
CPoint Point;
CCircle Circle;
Center x=0
CPiont Point;//重复定义
CCircle Circle;//重复定义
很明显你重复定义了呀
错误应该出现在下面几句里;
CPoint Center;
CPoint Point;
CCircle Circle;
Center x=0
CPiont Point;//重复定义
CCircle Circle;//重复定义
很明显你重复定义了呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
IsInCircle在圆内的话,根据解析几何知识 (x-x0)^2 +(y-y0)^2 <=r^2;
错误应该是
public; ==》public: 分号与冒号搞错了
错误应该是
public; ==》public: 分号与冒号搞错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Center x=0
main()里的这句
main()里的这句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
报什么错贴出来啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询