Amazon.com Widgets My Finished 11.2 Class Implementation
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2013, 10:00:13 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 11
| | | |-+  My Finished 11.2 Class Implementation
Pages: [1]   Go Down
Print
Author Topic: My Finished 11.2 Class Implementation  (Read 288 times)
Qpido
Newbie
*
Posts: 7






« on: May 04, 2012, 04:21:12 AM »

I decided to use what we've learned so far and make this scenario:

Code: (Objective-C)
#import "Fraction+Comparison.h"

@implementation Fraction (Comparison)

-(BOOL) isEqualTo:(Fraction *) f
{
    [self reduce];
    [f reduce];
   
    if ( self.numerator == f.numerator && self.denominator == f.denominator)
        return YES;
    else {
        return NO;
    }
}

-(int) compare: (Fraction *) f
{
    [self reduce];
    [f reduce];
   
    if ( (double)self.numerator / self.denominator > (double) f.numerator / f.denominator)
        return -1;
    else if ( [self isEqualTo:f] == YES)
        return 0;
    else {
        return 1;
    }
}

@end

Hope you enjoy!

Q
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.