// 4.5 연습문제 7번
#import <Foundation/Foundation.h>
-(void) setWidth : (int) w;
-(void) setHeight : (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) perimeter;
@end
@implementation Rectangle
{int width, height;
}
-(void) setWidth : (int) w;
{
width = w;
}
-(void) setHeight : (int) h;
{
height = h;
}
-(int) width;
{
return width;
}
-(int) height;
{
return height;
}
-(int) area;
{
return width * height;
}-(int) perimeter;
{
return 2 * (width + height);
}
@end
{
@autoreleasepool {
Rectangle *rectangleEx7 = [[Rectangle alloc] init];[rectangleEx7 setWidth: 10];
[rectangleEx7 setHeight: 24];
NSLog(@"Width %i, height %i, Area of rectangle is %i and Perimeter is %i",
[rectangleEx7 width], [rectangleEx7 height], [rectangleEx7 area], [rectangleEx7 perimeter]);}
return 0;
}
댓글 없음:
댓글 쓰기