First Objective C

//
//  main.m
//  hello-objc
//
//  Created by test5d on 14-9-29.
//  Copyright (c) 2014年 test5d. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Fraction : NSObject

-(void) print;
-(void) setNumberator: (int) n;
-(void) setDenominator:(int) d;

@end

@implementation Fraction
{
    int numberator;
    int denominator;
}
-(void) print{
    NSLog(@"%i/%i",numberator,denominator);
}
-(void) setNumberator:(int)n{
    numberator = n;
}
-(void)setDenominator:(int)d{
    denominator = d;
}

@end



int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Fraction *frac1 = [[Fraction alloc] init];
        [frac1 setNumberator: 3];
        [frac1 setDenominator: 4];
        [frac1 print];
    }
    return 0;
}

 

posted @ 2014-09-29 13:54  庚武  Views(194)  Comments(0Edit  收藏  举报