黑马程序员技术交流社区
标题:
大家给看看哪里出错了,五个警告
[打印本页]
作者:
ch8898163
时间:
2014-10-9 11:58
标题:
大家给看看哪里出错了,五个警告
这是我跟着老师的代码敲的,6.设计一个类Circle,用来表示二维平面中的圆
1> 属性
* double radius (半径)
* Point2D *point (圆心)
2> 方法
* 属性相应的set和get方法
* 设计一个对象方法判断跟其他圆是否相交(重叠返回YES,否则返回NO)
* 设计一个类方法判断两个圆是否相交(重叠返回YES,否则返回NO)
然后敲完之后就5个警告,看不出来在哪。。。谁帮帮忙~~~~我只是稍微按自己的理解改动了点成员变量和方法中的变量名。。。
#import <Foundation/Foundation.h>
#import <math.h>
@interface Point2D : NSObject
{
double _x;
double _y;
}
- (void)setX:(double)x;
- (double)x;
- (void)setY:(double)y;
- (double)y;
- (void)setX:(double)x andY:(double)y;
- (double)distanceWithOther :(Point2D *)other;
+ (double)distanceWithPonit1:(Point2D *)point1 andPoint2:(Point2D *)point2;
@end
@implementation Point2D
- (void)setX:(double)x
{
_x = x;
}
- (double)x
{
return _x;
}
- (void)setY:(double)y
{
_y = y;
}
- (double)y
{
return _y;
}
- (void)setX:(double)x andY:(double)y
{
_x = x;
_y = y;
}
- (double)distanceWithOther :(Point2D *)other
{
return [Point2D distanceWithPonit1:self andPoint2:other];
}
+ (double)distanceWithPonit1:(Point2D *)point1 andPoint2:(Point2D *)point2
{
double xDelta = [point1 x] - [point2 x];
double xDeltaPingFang = pow(xDelta, 2);
double yDelta = [point1 y] - [point2 y];
double yDeltaPingFang = pow(yDelta, 2);
return sqrt(xDeltaPingFang + yDeltaPingFang);
}
@end
@interface Circle : NSObject
{
double _radius;
Point2D *_point;
}
- (void)setRadius:(double)radius;
- (double)radius;
- (void)setPoint:(Point2D *)point;
- (Point2D *)point;
- (BOOL)isInteraceWithOther:(Circle *)other;
+ (BOOL)isInteraceBetweenCircle1:(Circle *)circle1 andCircle2:(Circle *)circle2;
@end
@implementation Circle
- (void)setRadius:(double)radius
{
_radius = radius;
}
- (double)radius
{
return _radius;
}
- (void)setPoint:(Point2D *)point
{
_point = point;
}
- (Point2D *)point
{
return _point;
}
- (BOOL)isInteraceWithOther:(Circle *)other
{
return [Circle isInteraceBetweenCircle1:self andCircle2:other];
}
+ (BOOL)isInteraceBetweenCircle1:(Circle *)circle1 andCircle2:(Circle *)circle2
{
Point2D *point1 = [circle1 point];
Point2D *point2 = [circle2 point];
double distance = [point1 distanceWithOther:point2];
double radiusSum = [circle1 radius] + [circle2 radius];
return distance < radiusSum;
}
@end
int main ()
{
Circle *c1 = [Circle new];
[c1 setRadius:2];
Point2D *p1 = [Point2D new];
[p1 setX:10 andY:10];
[c1 setPoint :p1];
Circle *c2 = [Circle new];
[c2 setRadius:2];
Point2D *p2 = [Point2D new];
[p2 setX:13 andY:14];
[c2 Point2D :p2];
BOOL b1 = [c1 isInteractWithOther:c2];
BOOL b2 = [Circle isInteractBetweenCircle1:c1 andCircle2:c2];
NSLog(@"%d %d", b1, b2);
return 0 ;
}
作者:
flyfuckadmin
时间:
2014-10-9 12:03
为什么有笑脸??
作者:
Lizzie
时间:
2014-10-9 14:22
额 你别直接粘贴啊 有插入代码的按钮 要不然看着乱 还容易被解析成表情
作者:
米匠
时间:
2014-10-9 16:51
这个是OC吧,还没学到那。。。
作者:
赵志文
时间:
2014-10-9 22:25
目测 缺少冒号 ,冒号也是方法名的一部分
作者:
赵志文
时间:
2014-10-9 22:26
要不就是类型没用括号包起来
作者:
易孟飞
时间:
2014-10-9 22:49
第35行有语法错误
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2