Amazon.com Widgets Exercice 8.8
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 23, 2014, 10:16:59 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
|-+ Programming in Objective-C, 4th edition
| |-+ Exercises
| | |-+ Chapter 8
| | | |-+ Exercice 8.8
Pages: [1] Go Down
Print
Author Topic: Exercice 8.8 (Read 539 times)
SceL
Newbie
*
Posts: 4


Email




on: January 23, 2012, 12:03:23 AM

Code: (Objective-C)
//
//  main.m
//  OC-A8E8
//
//  Created by jetphoto webone on 23/01/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Rectangle : NSObject

@property int width, height;

-(void) setWidth: (int) w andHeight: (int) h;
-(void) draw;

@end

@implementation Rectangle

@synthesize width, height;

-(void) setWidth: (int) w andHeight: (int) h {
    width = w;
    height = h;
}

-(void) draw {
    for (int i = 0, j = 1; i <= height + 1; j++)
    {
        if (i == 0 && j % width != 0) printf("-");
        else if (i == height + 1 && j % width != 0) printf("-");
        else if (j % width == 1) printf("|");
        else if (j % width == 0 && (i == 0 || i == height + 1 ) ) {
            printf("-\n");
            i++;
        }
        else if (j % width == 0){
            printf("|\n");
            i++;
        }
        else printf(" ");
    }
}

@end
   
int main (int argc, const char * argv[])
{

    @autoreleasepool {
       
        Rectangle *myRect = [[Rectangle alloc] init];
        [myRect setWidth: 20 andHeight: 10];
       
        [myRect draw];
       
    }
    return 0;
}
Logged
eagle74
Newbie
*
Posts: 24


www.cucinareblog.it


WWW Email




Reply #1 on: May 06, 2012, 11:01:57 AM

this is my draw method:
Code: (Objective-C)
-(void) draw
{
    int i;
    int k;
   
    for (i=1; i<=self.width; i++)
    {
        printf("-");
    }
    printf("\n");
   
    i=0;
   
    for (i=1; i<=(self.height); i++)
    {
        printf("|");
       
        for (k=1; k<=(self.width-2); k++)
        {
            printf(" ");
        }
        printf("|");
         printf("\n");
    }
    i=0;
   
    for (i=1; i<=self.width; i++)
    {
        printf("-");
    }
    printf("\n");

}

Logged

"The more i know people the more i love dogs."Socrate
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.