Amazon.com Widgets my answer for chapter 3 exercise 7
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2014, 10:23:55 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 3
| | | |-+ my answer for chapter 3 exercise 7
Pages: [1] Go Down
Print
Author Topic: my answer for chapter 3 exercise 7 (Read 1982 times)
h00ligan
Newbie
*
Posts: 10


Email




on: February 01, 2012, 05:24:10 PM

// ------------- @interface-------------

@interface XYpoint: NSObject

-(void)print;
-(void)setX: (int) x;
-(void)setY: (int) y;

@end

//----------- @implementation----------

@implementation XYpoint
{
    int xCoord;
    int yCoord;
   
}

-(void) print
{
    NSLog(@"%i,%i", xCoord, yCoord);
}

-(void) setX: (int) x
{
    xCoord = x;
}

-(void) setY: (int) y
{
    yCoord = y;
}


@end

// ------------ program section ---------

int main (int argc, const char * argv[])
{

    @autoreleasepool {
       
        // insert code here...
        XYpoint *coord1 = [[XYpoint alloc] init];
       
        [coord1 setX: 35];
        [coord1 setY: 57];
       
        NSLog(@"The coordinates are:");
        [coord1 print];
       
       
    }
    return 0;
}



Anyone see any issues? Runs fine, just wondering if I made any mistakes
Logged
h00ligan
Newbie
*
Posts: 10


Email




Reply #1 on: February 01, 2012, 05:39:33 PM

returning them independently \\

// ------------- @interface-------------

@interface XYpoint: NSObject

-(void)print;
-(void)setX: (int) x;
-(void)setY: (int) y;
-(int)xCoord;
-(int)yCoord;

@end

//----------- @implementation----------

@implementation XYpoint
{
    int xCoord;
    int yCoord;
   
}

-(void) print
{
    NSLog(@"%i,%i", xCoord, yCoord);
}

-(void) setX: (int) x
{
    xCoord = x;
}

-(void) setY: (int) y
{
    yCoord = y;
   
}

-(int) yCoord
{
    return yCoord;
}

-(int) xCoord
{
    return xCoord;
}

@end

// ------------ program section ---------

int main (int argc, const char * argv[])
{

    @autoreleasepool {
       
        // insert code here...
        XYpoint *coord1 = [[XYpoint alloc] init];
       
        [coord1 setX: 35];
        [coord1 setY: 57];
       
        NSLog(@"The coordinates are: x=%i, y=%i", [coord1 xCoord], [coord1 yCoord]);
       
    }
    return 0;
}
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #2 on: February 02, 2012, 10:36:06 AM

It all looks good!

Cheers,

Steve
Logged
cnshzj007
Newbie
*
Posts: 1


Email




Reply #3 on: February 25, 2012, 01:27:35 AM

In the first post, it only has the setters without the getters. Do i guess right?
Logged
seerex
Full Member
***
Posts: 177


Email




Reply #4 on: February 25, 2012, 06:10:32 AM

Yep, thats true :=)
Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
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.