24小时热门版块排行榜    

查看: 265  |  回复: 1

我是王后雄

新虫 (初入文坛)

[交流] 自己写的OC代码但是出了好多错误,求大神指点

Sample Text



#import<Foundation/Foundation.h>

@interface Shape:NSObject
{
float area;
}
-(void)getAreafloat)area;

@end


@implementation Shape
-(void)getAreafloat)a
{

}

@end

@interface Circle:Shape
{
int radius;
}
@end


@implementation Circle
-(id)init
{
if(self=[super init])
{
radius=0;
}
return (self);
}
-(id)initWithRadiusint)_radius
{
if(self=[super init])
{
radius=_radius;
a=_radius*_radius*3.14;
}
return (self);
}
-(void)getAreafloat)a
{
area=a;
}
@end



@interface Rectangle:Shape
{
int length;
int width;
}
@end

@implementation Rectangle
-(id)init
{
if(self=[super init])
{
length=0;
width=0;
}
return (self);
}


-(id)initWithLengthint)_length WithWidthint)_width
{
if(self=[super init])
{
length=_length;
width=_width;
a=_length*_width;
}
return (self);
}
-(void)getAreafloat)a
{
area=a;
}
@end

int main()
{
Circle *circle=[[Circle alloc]initWithRadius:5];
NSLog(@"Circle area:%f",[circle getArea]);

Rectangle *rect=[[Rectangle alloc]initWithLength:5 WithWidth:6];
NSLog(@"Rectangle area:%f",[rectgetArea]);

[circle release];
[rectangle release];

return 0;
}



Sample Text

编程实现:Shape类
1.成员变量:area
2.获取面积的方法:getArea

Circle继承Shape类
Circle成员变量:radius
在初始化函数内对radius进行初始化

Rectangle继承Shape:
Rectangle成员变量:length,width
在初始化函数内对lenth,width进行初始化


好多错误实在不会弄,求帮我指点一下
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

我是王后雄

新虫 (初入文坛)

直接上图片好了
自己写的OC代码但是出了好多错误,求大神指点
test1.PNG


自己写的OC代码但是出了好多错误,求大神指点-1
test2.PNG


自己写的OC代码但是出了好多错误,求大神指点-2
test3.PNG


自己写的OC代码但是出了好多错误,求大神指点-3
teat4.PNG


自己写的OC代码但是出了好多错误,求大神指点-4
teat5.PNG

2楼2015-06-15 10:37:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 我是王后雄 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见