@fiy-fish
2015-07-14T19:39:04.000000Z
字数 664
阅读 1339
Objective-c
// day02-03-练习
//
// Created by Aaron on 15/7/2.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Circle.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Circle *c = [[Circle alloc] initWithR:10.0f];
NSLog(@"周长:%.2f",[c zhouChang]);
NSLog(@"面积:%.2f",[c mianJi]);
}
return 0;
}
#import <Foundation/Foundation.h>
//创建一个圆,求周长和面积
@interface Circle : NSObject
{
float _r;
}
-(instancetype)initWithR:(float)r;
-(float)zhouChang;
-(float)mianJi;
@end
#import "Circle.h"
@implementation Circle
-(instancetype)initWithR:(float)r
{
if(self = [super init])
{
_r = r;
}
return self;
}
-(float)zhouChang
{
return 2*M_PI*_r;
}
-(float)mianJi
{
return M_PI*_r*_r;
}
@end