一、IOS類和方法

趙明威發表於2015-11-10
//
//  main.m
//  prog1
//
//  Created by 趙明威 on 15/11/8.
//  Copyright © 2015年 趙明威. All rights reserved.
//

#import <Foundation/Foundation.h>
/** @interface 部分**/
@interface Fraction : NSObject
- (void) print;
- (void) setNumerator;
- (void) setDenminator;
-(int)numerator;
-(int)denminator;
@end

/** implementation **/
@implementation Fraction
{
    int numerator;
    int denminator;
}
-(void)print
{
    NSLog(@"%i/%i",numerator,denminator);
}
-(void)setNumerator:(int) n
{
    numerator = n;
}

-(void)setDenminator:(int) d
{
    denminator = d;
}

-(int)numerator
{
    return numerator;
}

-(int)denminator
{
    return denminator;
}
@end

int main(int argc, const char * argv[]) {
@autoreleasepool {
    Fraction *first1 = [Fraction new];
    Fraction *first2 = [Fraction new];
    [first1 setNumerator:3];
    [first1 setDenminator:10];
    [first1 print];
    NSLog(@"first1 numerator is %i",[first1 numerator]);

    [first2 setNumerator:4];
    [first2 setDenminator:7];
    [first2 print];
    NSLog(@"first2 numerator is %i",[first2 denminator]);

    }
    return 0;
}

相關文章