//
// 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;
}