zoukankan      html  css  js  c++  java
  • OC3_MyRect

    //
    //  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:10 andWidth:5];
            [rect printArea];
        }
        return 0;
    }
  • 相关阅读:
    setlocale
    c++的 程序实体 作用域 名空间 变量生存期概念理解
    本人的Ubuntu 10.04配置清单
    hadoopStreamming 编程 Angels
    级联 mapreduce (Cascading Mapreduce) Angels
    委托
    OPC和XML/SOAP/Web Services
    实例管理2(会话服务)
    实例管理3()
    操作(Operation)
  • 原文地址:https://www.cnblogs.com/0515offer/p/4564541.html
Copyright © 2011-2022 走看看