An exercise about drawing a rectangle class using the printf function -
so problem next :
"write method rectangle class called draw draws rectangle using dashes , vertical bar characters. next code sequence
rectangle *myrect = [[rectangle alloc]init]; [myrect setwidth : 10 andheight : 3]; [myrect draw];
would produce next output : "
(i cant show image rectangle made out of "-" dashes , "|" bar characters. dashes width , bar characters height.)
i've started doing method :
{ int n; ( n = 1 ; n <= self.width ; ++n) printf ("-"); ( n = 1 ; n <= self.height ; ++n){ printf ("\n|"); } printf("\n"); ( n = 1 ; n <= self.width ; ++n){ printf ("-"); }
but seems not going work , cant display outer (|) lines . help me on one?
i believe working in objective-c, here simple set of code tested in c should translate on easily:
void printrectangle(int width, int height) { int n; int z; printf(" "); (n = 1 ; n <= width ; n++) printf ("-"); printf("\n"); ( n = 1 ; n <= height ; n++) { printf ("|"); for(z = 1; z <= width; z++) printf(" "); printf("|\n"); } printf(" "); ( n = 1 ; n <= width ; ++n) printf ("-"); printf("\n"); }
output width = 10, height = 5
---------- | | | | | | | | | | ----------
printf
No comments:
Post a Comment