黑马程序员技术交流社区
标题:
有笑脸,这个是按照插入的,大家看看。。五警告
[打印本页]
作者:
ch8898163
时间:
2014-10-9 21:48
标题:
有笑脸,这个是按照插入的,大家看看。。五警告
6.设计一个类Circle,用来表示二维平面中的圆
1> 属性
* double radius (半径)
* Point2D *point (圆心)
2> 方法
* 属性相应的set和get方法
* 设计一个对象方法判断跟其他圆是否相交(重叠返回YES,否则返回NO)
* 设计一个类方法判断两个圆是否相交(重叠返回YES,否则返回NO)
#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 ;
}
复制代码
作者:
陌生爱人
时间:
2014-10-10 15:38
第141 和 143 你那个单词isInteract 你在定义的时候写的是isInterace 你把两个t改成e
139行 Point2D改成 setPoint
我这边看就没错误和警告了啊
作者:
ch8898163
时间:
2014-10-12 14:46
陌生爱人 发表于 2014-10-10 15:38
第141 和 143 你那个单词isInteract 你在定义的时候写的是isInterace 你把两个t改成e
139行 Point2D改 ...
好的,谢谢、还是我比较粗心了。太感谢了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2