私はObjective-Cを初めて使用しますが、ここでどこが間違っているのか完全にはわかりません。正方形の面積と周囲長を印刷するプログラムを取得しようとしています。プログラムは、宣言されていない識別子を境界メソッドと領域メソッドに送信していることを通知しています
#import <Foundation/Foundation.h>
@interface Rectangle : NSObject
{
int width;
int height;
}
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) perimeter;
@end
@implementation Rectangle
-(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 + 2*height);
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Rectangle *rect1 = [[Rectangle alloc] init];
[rect1 setWidth:2];
[rect1 setHeight:7];
NSLog(@"The perimeter of rect1 is: %i and the area is: %i", area, area);
}
return 0;
}