Using self.numerator self.denominator?

Here is my 11.1 broken into multiple files.

**Fraction.h**#import <Foundation/Foundation.h>

@interface Fraction : NSObject

@property int numerator, denominator;

-(void) print;

-(void) setTo: (int) n over: (int) d;

-(double) convertToNum;

-(void) reduce;

@end

**Fraction+MathOps.h**#import "Fraction.h"

@interface Fraction (Mathops)

-(Fraction *) add: (Fraction *) f;

-(Fraction *) sub: (Fraction *) f;

-(Fraction *) mul: (Fraction *) f;

-(Fraction *) div: (Fraction *) f;

-(Fraction *) inv;

@end

**Fraction+MathOps.m**#import "Fraction+MathOps.h"

@implementation Fraction (MathOps)

-(Fraction *) add: (Fraction *) f

{

// To add two fractions

Fraction *result = [[Fraction alloc] init];

result.numerator = (self.numerator * f.denominator) + (self.denominator * f.numerator);

result.denominator = self.denominator * f.denominator;

[result reduce];

return result;

}

-(Fraction *) sub: (Fraction *) f

{

// To sub two fractions

Fraction *result = [[Fraction alloc] init];

result.numerator = (self.numerator * f.denominator) - (self.denominator * f.numerator);

result.denominator = self.denominator * f.denominator;

[result reduce];

return result;

}

-(Fraction *) mul: (Fraction *) f

{

// To mul two fractions

Fraction *result = [[Fraction alloc] init];

result.numerator = self.numerator * f.numerator;

result.denominator = self.denominator * f.denominator;

[result reduce];

return result;

}

-(Fraction *) div: (Fraction *) f

{

// To div two fractions

Fraction *result = [[Fraction alloc] init];

result.numerator = self.numerator * f.denominator;

result.denominator = self.denominator * f.numerator;

[result reduce];

return result;

}

-(Fraction *) inv

{

// To invert a fraction

Fraction *result = [[Fraction alloc] init];

result.numerator = self.denominator;

result.denominator = self.numerator;

[result reduce];

return result;

}

@end

**main.m** (old Xcode version)

#import "Fraction.h"

int main (int argc, const char * argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

Fraction *a = [[Fraction alloc] init];

Fraction *b = [[Fraction alloc] init];

Fraction *result;

[a setTo: 1 over: 3];

[b setTo: 2 over: 5];

[a print]; NSLog(@" +"); [b print]; NSLog(@"----");

result = [a add: b];

[result print];

NSLog (@"\n");

[a print]; NSLog(@" -"); [b print]; NSLog(@"----");

result = [a sub: b];

[result print];

NSLog (@"\n");

[a print]; NSLog(@" *"); [b print]; NSLog(@"----");

result = [a mul: b];

[result print];

NSLog (@"\n");

[a print]; NSLog(@" /"); [b print]; NSLog(@"----");

result = [a div: b];

[result print];

NSLog (@"\n");

[b print]; NSLog(@"inverted"); NSLog(@"----");

result = [b inv];

[result print];

NSLog (@"\n");

[pool drain];

return 0;

}