Amazon.com Widgets I don't understand -(void) add: (Fraction *) f;
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 12:54:46 AM
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
| |-+  Chapter Study
| | |-+  Chapter 7 - More on Classes
| | | |-+  I don't understand -(void) add: (Fraction *) f;
Pages: [1]   Go Down
Print
Author Topic: I don't understand -(void) add: (Fraction *) f;  (Read 1157 times)
isaiasMac
Newbie
*
Posts: 18


isaias1706
Email




« on: August 25, 2010, 10:29:38 PM »

can anybody explain why use this:

numerator = numerator * f.denominator + denominator * f.numerator;
denominator = denominator * f.denominator;

for this:

numerator = numerator * denominator + denominator *  numerator;
denominator = denominator * denominator;

Please help me !!

    thank you !!
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #1 on: August 28, 2010, 09:54:05 PM »

When you write just numerator or denominator you refer to the receiver's numerator and denominator.   Since we called the Fraction argument that is passed to the add: method f, you need to write f.numerator and f.denominator to refer to its numerator and denominator.

So when you write

Code: (Objective-C)
[fract1 add: fract2];

the receiver of the add: message is fract1, and the argument is fract2.  So in the add: method, numerator and denominator refer to fract1's (the receiver's) numerator and denominator, while f.numerator and f.denominator refer to fract2's (the argument's) numerator and denominator, respectively.

Cheers,

Steve
« Last Edit: August 30, 2010, 04:40:31 AM by skochan » Logged
isaiasMac
Newbie
*
Posts: 18


isaias1706
Email




« Reply #2 on: August 29, 2010, 02:04:04 PM »

thank you Mr. skochan
Logged
GM3131
Newbie
*
Posts: 1






« Reply #3 on: April 10, 2011, 01:49:30 PM »

This explanation was extremely helpful.  I was dazed at first but now I believe I understand 7.3 now.

Just getting started on this stuff, this Web site has been awesome in helping me understand things.

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