Amazon.com Widgets Program 11.1 Page 228 (221 3rd edition)
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 23, 2014, 11:59:16 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
| |-+ Program Examples
| | |-+ Chapter 11
| | | |-+ Program 11.1 Page 228 (221 3rd edition)
Pages: [1] Go Down
Print
Author Topic: Program 11.1 Page 228 (221 3rd edition) (Read 1764 times)
PumaSpeedDrift
Newbie
*
Posts: 10


Email




on: July 28, 2010, 09:49:08 AM

I know I have an earlier version of the book, but could not find a correction, unless I am wrong in reading the example:

In the book, these two methods:

Code: (Objective-C)
-(Fraction *) mul: (Fraction *) f
{
Fraction *result = [[Fraction alloc] init];
//*********

[result setTo: numerator * f.numerator  
over: denominator * f.denominator];

//********
[result reduce];
return result;
}
-(Fraction *) div: (Fraction *) f
{
Fraction *result = [[Fraction alloc] init];
//**********

[result setTo: numerator * f.denominator              
over: denominator * f.numerator];

//*********
[result reduce];
return result;
}

Wouldn't they produce the same result since no math was really applied?
Should they have followed these formulas?

numerator = ((a*d) * (b*c)) / (b * d)   //For Multiply

and

 numerator = ((a*d) / (b*c)) / (b * d)  //For Division

since the output in the book shows otherwise?
Last Edit: August 04, 2011, 08:54:16 AM by fujilla Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: August 02, 2010, 01:05:53 PM

When you multiply two fractions you simply multiply the two numerators by each other and the two denominators by each other.  When you divide two fractions, it's the same as multiplying the first by the inverse of the second.

Cheers,

Steve Kochan
Logged
PumaSpeedDrift
Newbie
*
Posts: 10


Email




Reply #2 on: August 09, 2010, 06:03:11 AM

My bad, I didn't realize that was actually happening in the code, I was wrong.  I mis-read the code. ( I think I need to pay closer attention to what I am reading and seeing.)

Thank you Steve!
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.