Amazon.com Widgets answer from Huiqi
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 07:44:47 AM
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
|-+  Old Stuff
| |-+  Webcast Series Part I, Sept. 1 - 24
| | |-+  Chapter 4, Exercise 7
| | | |-+  answer from Huiqi
Pages: [1]   Go Down
Print
Author Topic: answer from Huiqi  (Read 678 times)
Huiqi
Newbie
*
Posts: 8






« on: September 08, 2009, 10:07:05 AM »

@interface Rectangle: NSObject
{
   int width;
   int height;
}
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) perimeter;
@end

@implementation Rectangle
-(void) setWidth: (int) w
{
   width = w;
}
-(void) setHeight: (int) h
{
   height = h;
}
-(int) width
{
   return width;
}
-(int) height
{
   return height;
}
-(int) area
{
   return width*height;
}
-(int) perimeter
{
   return 2*(width+height);
}
@end
   

#import <Foundation/Foundation.h>

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

    // insert code here...
   
   [rect1 setWidth: 4];
   [rect1 setHeight: 3];
   
    NSLog(@"area = %i, perimeter = %i", [rect1 area],[rect1 perimeter]);
    [rect1 release];
   [pool drain];
    return 0;
}
Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #1 on: September 16, 2009, 11:37:06 AM »

Looks good, Huiqi!

Now rewrite it to use the @property directive, synthesize your accessor methods, and use the dot operator.

Cheers,

Steve Kochan
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.