Hi! Well I'm reading Stephen Kochan's Book: Programming in Objective-C 2.0 and one of the excersizes is to draw a rectangle based on height and width using the | and _ characters, e.g.:
____
| |
| |
| |
____
Here's my code:
@interface
@implementation
main
And here's the output:
And it keeps on going for a LONG time (never tested to see if it DOES end)
Any help greatly appreciated! Thanks!!!
-iMaster
____
| |
| |
| |
____
Here's my code:
@interface
Code:
#import <Foundation/Foundation.h>
@interface Rectangle: NSObject {
int height;
int width;
}
@property int height, width;
-(void) draw;
-(void) getMeas;
@end
@implementation
Code:
#import "Drawing.h"
@implementation Rectangle
@synthesize height, width;
-(void) getMeas;
{
int usrHeight, usrWidth;
scanf("%i %i", &usrHeight, &usrWidth);
height = usrHeight;
width = usrWidth;
}
-(void) draw {
int c;
for(c = 0; c != height; ++c) {
NSLog(@"%i", &height);
NSLog(@"_");
}
int d;
int e;
do {
NSLog(@"|");
do {
NSLog(@" ");
++d;
} while(d != c);
NSLog(@"|");
++e;
} while(e != height);
c = 0;
do {
NSLog(@"_");
++c;
} while (c != height);
}
@end
Code:
#import "Drawing.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Rectangle *myRect = [[Rectangle alloc] init];
// insert code here...
NSLog(@"Please enter your height and width (in that order)");
[myRect getMeas];
[myRect draw];
[myRect release];
[pool drain];
return 0;
}
And here's the output:
Code:
2009-09-01 20:40:46.394 Drawing Application[14128:903] Please enter your height and width (in that order)
4 7
2009-09-01 20:40:53.916 Drawing Application[14128:903] 1068468
2009-09-01 20:40:53.917 Drawing Application[14128:903] _
2009-09-01 20:40:53.918 Drawing Application[14128:903] 1068468
2009-09-01 20:40:53.919 Drawing Application[14128:903] _
2009-09-01 20:40:53.919 Drawing Application[14128:903] 1068468
2009-09-01 20:40:53.920 Drawing Application[14128:903] _
2009-09-01 20:40:53.921 Drawing Application[14128:903] 1068468
2009-09-01 20:40:53.921 Drawing Application[14128:903] _
2009-09-01 20:40:53.922 Drawing Application[14128:903] |
2009-09-01 20:40:53.922 Drawing Application[14128:903]
2009-09-01 20:40:53.922 Drawing Application[14128:903]
2009-09-01 20:40:53.923 Drawing Application[14128:903]
2009-09-01 20:40:53.923 Drawing Application[14128:903]
2009-09-01 20:40:53.924 Drawing Application[14128:903]
2009-09-01 20:40:53.924 Drawing Application[14128:903]
2009-09-01 20:40:53.924 Drawing Application[14128:903]
2009-09-01 20:40:53.925 Drawing Application[14128:903]
2009-09-01 20:40:53.925 Drawing Application[14128:903]
2009-09-01 20:40:53.925 Drawing Application[14128:903]
2009-09-01 20:40:53.926 Drawing Application[14128:903]
...
2009-09-01 20:40:58.332 Drawing Application[14128:903]
And it keeps on going for a LONG time (never tested to see if it DOES end)
Any help greatly appreciated! Thanks!!!
-iMaster