Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 09:06:47 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 ... 4 5 [6]   Go Down
  Print  
Author Topic: Chapter 3: Exercice program  (Read 37790 times)
mcw5445
Newbie
*
Posts: 1


Email
« Reply #75 on: July 26, 2011, 09:43:49 PM »

So I have done a few online tutorials before and they were great but I needed a little more help on some of the concepts. That is to explain why I separated the files on this program. It ran correctly (after I sorted out the first 10 errors,  Cheesy)

// @ interface section
#import <Foundation/Foundation.h>


@interface Myxypoint : NSObject {

   int xcord;
   int ycord;
}

-(void) setXval: (int) x;
-(void) setYval: (int) y;
-(int) xcord;
-(int) ycord;

@end

// @ implementation section

#import "Myxypoint.h"


@implementation Myxypoint


-(void) setXval: (int) x{
   xcord = x;
}
-(void) setYval: (int) y{
   ycord = y;
}
-(int) xcord{
   return xcord;
}
-(int) ycord{
   return ycord;
}
@end

// program section

#import <Foundation/Foundation.h>
#import "Myxypoint.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   Myxypoint *mp = [[Myxypoint alloc]init];
   
   [mp setXval: 20];
   [mp setYval: 50];
   
   NSLog(@"The latitude is %i and the longitude is %i", [mp xcord],[mp ycord]);
   [mp release];
   
    [pool drain];
    return 0;
}

Logged
Pages: 1 ... 4 5 [6]   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.