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;
    }
  • 相关阅读:
    HDU 3695 Computer Virus on Planet Pandora
    codeforces 706D Vasiliy's Multiset
    HDU 2222 Keywords Search
    POJ 2348 Euclid's Game
    HDU 1079 Calendar Game
    js选项卡的实现方法
    实现鼠标悬浮切换标题和内容
    js实现鼠标悬浮切换 setTab 代码实现
    自学Node.js: WebStorm+Node.js开发环境的配置
    windows 下安装nodejs
  • 原文地址:https://www.cnblogs.com/0515offer/p/4564541.html
Copyright © 2011-2022 走看看