Amazon.com Widgets Answer from Jeff in Calgary
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2013, 08:00:49 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
|-+  Old Stuff
| |-+  Webcast Series Part I, Sept. 1 - 24
| | |-+  Chapter 4, Exercise 7
| | | |-+  Answer from Jeff in Calgary
Pages: [1]   Go Down
Print
Author Topic: Answer from Jeff in Calgary  (Read 655 times)
ReachWest
Newbie
*
Posts: 6







« on: September 04, 2009, 07:11:54 PM »

Here is my solution for Page 74 - Excercise 7 (Chapter 4). Appears to work.

The Implementation File:
Code: (Objective-C)
#import "Rectangle.h"

@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 (width + height) * 2;
}

@end

And the Main File:
Code: (Objective-C)
#import <Foundation/Foundation.h>
#import "Rectangle.h"

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

myRectangle = [[Rectangle alloc] init];

[myRectangle setWidth: 5 ];
[myRectangle setHeight: 6 ];

NSLog(@"The rectangle is %i wide by %i high", [myRectangle width], [myRectangle height]);
NSLog(@"Perimeter is %i and the area contained in the rectangle is %i.", [myRectangle perimeter], [myRectangle area]);

[myRectangle release];
    [pool drain];
    return 0;
}

Logged
skochan
Administrator
Hero Member
*****
Posts: 3104







« Reply #1 on: September 08, 2009, 08:37:56 AM »

Good job!  No comments.

Cheers,

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