Amazon.com Widgets Chapter 4 Exercise 7
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 23, 2014, 06:03:57 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
| |-+ Answers to Exercises
| | |-+ Chapter 4
| | | |-+ Chapter 4 Exercise 7
Pages: [1] Go Down
Print
Author Topic: Chapter 4 Exercise 7 (Read 650 times)
monster
Newbie
*
Posts: 11






on: March 21, 2010, 05:23:55 PM


#import <Foundation/Foundation.h>

@interface Rectangle : NSObject

{
   int width, 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

// Program Section


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   Rectangle *myRectangle = [[Rectangle alloc] init];
   
   
   
   // insert code here...  [myConversion setFahrenheit: 27];   
   [myRectangle setWidth: 2];
   [myRectangle setHeight: 5];
   
   NSLog (@"\n\n Width: %i \n Height: %i \n Area: %i \n Perimeter: %i",
         [myRectangle width], [myRectangle height], [myRectangle area],
         [myRectangle perimeter]);
   
   [myRectangle release];
    [pool drain];
    return 0;
}
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.