OC3_MyRect

时间:2022-02-08 19:56:45
//
// MyRect.h
// OC3_MyRect
//
// Created by zhangxueming on 15/6/9.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface MyRect : NSObject
{
int _length;
int _width;
} - (id)initWithLength:(int)length andWidth:(int)width; - (int)length; - (int)width; - (void)setLength:(int)length andWidth:(int)width; - (int)area; - (void)printArea; @end
//
// MyRect.m
// OC3_MyRect
//
// Created by zhangxueming on 15/6/9.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "MyRect.h" @implementation MyRect - (id)initWithLength:(int)length andWidth:(int)width
{
self = [super init] ;
if (self) {
_length = length;
_width = width;
}
return self;
} - (int)length
{
return _length;
} - (int)width
{
return _width;
} - (void)setLength:(int)length andWidth:(int)width
{
_length = length;
_width = width;
} - (int)area;
{
return [self length] * [self width];
} - (void)printArea
{
NSLog(@"area = %i", [self area]);
} @end
//
// main.m
// OC3_MyRect
//
// Created by zhangxueming on 15/6/9.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
#import "MyRect.h" int main(int argc, const char * argv[]) {
@autoreleasepool {
MyRect *rect = [[MyRect alloc] init];
[rect setLength: andWidth:];
[rect printArea];
}
return ;
}

相关文章