Design Suggestions
If you need some discussion to help getting started
with this assignment, perhaps the following ideas will help:
First and foremost, DO NOT attempt to put all the code that writes the pattern
into one function. It is a bad design choice to try to pack a large amount
of detailed code into one function.
Instead divide up the work to be done and assign different parts of the work
to different functions.
Of course there may be many different logical ways to divide
the work. What my skeleton program suggests is that you
write a function
void makeTileRow (int b_width)
that is called with a width parameter (b_width),
and writes pieces of the pattern like this:
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
For example, if the value of the variable width is 3, the call
makeTileRow (width) ;
would write the tile pattern you see above to the screen.
The output above is part of what the program has to write
when the pattern is required to be three tiles wide.
Also, you could write a function
void makeHorizBorder (int b_width)
that inputs a width and writes the necessary sequence of asterisks
for a pattern of the indicated width.
For example, if the value of the variable width is 3, the call
makeHorizBorder (width) ;
writes this out:
****************************
As one example of how a program could possibly use these
functions in combination, note that, if width is equal to 3,
the sequence of calls:
makeHorizBorder (width) ;
makeTileRow (width) ;
makeHorizBorder (width) ;
writes out one row of tiles 3 tiles wide:
****************************
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
****************************
Each of the functions described above should use a loop to
write the correct amount of output, based on the value of
the parameter -- the width.
Your program needs to be able to write patterns with
multiple rows of tiles, according to the length input by the user.
For that, you will need to have other looping code in your program
nthat calls makeHorizBorder(width) and makeTileRow(width)
enough times and in the correct order.
WATCH OUT FOR FENCE POSTS
There are fence-post problems for you to solve when you write
functions like makeHorizBorder and makeTileRow.
Also another fence-post problem comes up when you write the
loop that outputs the tile pattern. For example, it takes three
calls to makeHorizBorder and two calls to makeTileRow to
make a pattern with two horizontal rows of tiles.
Look at this figure and make sure you see what I mean:
****************************
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
****************************
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
|888888|##|888888|##|888888|
****************************
Usually there's more than one approach that will work to solve a
fence-post problem. I put several sets of directions in my skeleton
program that indicate how to write code that 'solves a fence-post
problem.'
The skeleton program also directs you to write a helper function for
makeTileRow. It tells you to create a function that makes lines
like this:
|888888|##|888888|##|888888|
so that makeTileRow can rely
on calls to that helper function.
Although my skeleton does not call for it, you could
have separate functions to make individual small pieces of the
pattern - like these pieces:
|, ##, 888888,
*, **, and ******.
If you did that, your helper functions would have their own
helper functions.