Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
April 22, 2018, 09:06:46 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Lesson Seven  (Read 1383 times)
DavetheDog
Newbie
*
Posts: 1


« on: October 14, 2010, 07:45:21 PM »

Here is my solution to exercise 7. For myself, chapter 3 was very interesting and tough. Stephen does an excellent job but for some it is a new style of thinking. By reading the way other people wrote the same code it helped to clarify some things. I found Hugo's code to be different in a number of ways and forced me to think about it from a different perspective; it was good. I hope my terminology and train of thought or even formatting can be of help to others in grasping the idea.



#import <Foundation/Foundation.h>

/*___The @interface Section___
 
 This section defines the class, it's variables and it's methods. */

@interface XYPoint : NSObject
{
   int pointX;
   int pointY;
}

-(int) pointX;
-(int) pointY;
-(void) setPointX: (int) x;
-(void) setPointY: (int) y;

@end


/*___The @implementation Section___
 
 This section defines the methods for the class. */

@implementation XYPoint

-(int) pointX
{
   return pointX;
}
-(int) pointY
{
   return pointY;
}
-(void) setPointX: (int) x
{
   pointX = x;
}
-(void) setPointY: (int) y
{
   pointY = y;
}

@end


/*___The Program Section___
 
 This section is the code that runs the program. */

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
   XYPoint * myXYPoint = [[XYPoint alloc] init];
   
   //_Set the values of the pointX and pointY.
   
   [myXYPoint setPointX: 420];
   [myXYPoint setPointY: 421];
   
   //_Execution and follow through.
   
   NSLog(@"The treasure and be found at the coordinates (%i,%i).",
        [myXYPoint pointX], [myXYPoint pointY]);
   
   [myXYPoint release];
   
    [pool drain];
    return 0;
}
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.