Amazon.com Widgets Need help with 9.4 arithmetic
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2013, 09:07:10 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 9
| | | |-+  Need help with 9.4 arithmetic
Pages: [1]   Go Down
Print
Author Topic: Need help with 9.4 arithmetic  (Read 429 times)
electricb
Newbie
*
Posts: 6


Email




« on: April 26, 2012, 05:50:41 PM »

I've been trying to figure out this problem for over a day now, my method is called -(id) addTo (id) c. For the first step I declared result as an id object and then made that an instance of the complex class. After this step, I'm completely lost, how do we perform the arithmetic needed to define the method if we are using id objects? I can't simply use any dot notation which would make it possible to differentiate between the id objects, I can't use for example result.real = real + c.real because they are now id objects and I can't use any operators if I have to use brackets. Could somebody please toss me a bone here? This is what I have so far:

-(id) addTo:(id) c
{
    id result;
    
    result = [[Complex alloc] init];
  
    
    [result real];
    
return result;
}
« Last Edit: April 26, 2012, 06:17:22 PM by electricb » Logged
electricb
Newbie
*
Posts: 6


Email




« Reply #1 on: April 27, 2012, 08:23:59 PM »

-(id) addTo:(id)f
{
    return [self add: (id)f];
}


That's it!!?? Maybe I misunderstood the question, but I was under the impression that the add method for the Complex and Fraction classes had to be replaced with the modified add method, not used in conjunction with them. Is this solution correct, or did I miss the point entirely?
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.