Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 08:59:14 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: Exercise 7 is this what you had in mind?  (Read 1594 times)
SRC
Newbie
*
Posts: 19


Email
« on: October 15, 2010, 10:41:21 PM »

Is this OK for exercise 7? I don't seem to have control over the print out, it displays on 2 separate lines.
#import <Foundation/Foundation.h>
// exercise 7 chapter 3

   
@interface XYPoint : NSObject
{
   int Xpoint;
   int Ypoint;
}

   - (void) print;
   - (void) setXpoint: (int) x;
   - (void) setYpoint: (int) y;

@end

   @implementation XYPoint

   - (void) print
   {
      NSLog(@"(%i,%i)",Xpoint , Ypoint);
   }
   
   - (void) setXpoint: (int) x
   {
      Xpoint = x;
   }
   
   - (void) setYpoint: (int) y
   {
      Ypoint = y;
   }

   @end
   
// Program Section
   
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
   XYPoint *coordinates = [[XYPoint alloc] init];   
   
// set coordinates
   
   [coordinates setXpoint: 5];
   [coordinates setYpoint: 7];
   
// display coordinates
   
   NSLog(@"The Cartesian coordinates are "), [coordinates print];
   
       
   [coordinates 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.