Amazon.com Widgets pg 474 and 475
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 25, 2014, 02:09:32 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
|-+ Old Stuff
| |-+ Errata
| | |-+ 2nd printing
| | | |-+ pg 474 and 475
Pages: [1] Go Down
Print
Author Topic: pg 474 and 475 (Read 1013 times)
drshock
Newbie
*
Posts: 1






on: November 04, 2011, 03:38:18 PM

I just picked up the book, appears the latest - third edition second printing: August 2011.

The program 21.2 Fraction.m has an incomplete implementation printed for multiply and divide.  For example my copy has this on pg 474


     result.numerator = numerator * f.numerator


Obviously incomplete at this line.  Divide has a similar issue going onto pg 475.


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


FYI,

Logged
Fred
Newbie
*
Posts: 46






Reply #1 on: November 08, 2011, 07:36:43 AM

I'm using the PDF version of the book and it is complete showing the following on the two pages (except for two missing semi-colons as indicated).

-(Fraction *) multiply: (Fraction *) f
{
    Fraction *result = [[[Fraction alloc] init] autorelease];

    result.numerator = numerator * f.numerator; // added missing semi-colon
    result.denominator = denominator * f.denominator;
    [result reduce];

    return result;
}

-(Fraction *) divide: (Fraction *) f
{
    Fraction *result = [[[Fraction alloc] init] autorelease];
    result.numerator = numerator * f.denominator; // added missing semi-colon
    result.denominator = denominator * f.numerator];
    [result reduce];

    return result;
}

the mathematical formulas are correct.

Of course for the above to work with ARC under Xcode 4.2 you must remove the autorelease portion of the variable declarations as in:

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

Hope this helps.

Fred
Logged

Fred
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.