(Latest Revision: 09/14/2003)
What should the level-two program look like?
- The level-two program needs documentation for the main program,
for the functions called by the main program (they are called
level-two functions), and for the functions called by
the level-two functions (they are called level-three
functions.)
- The documentation for every function must tell what the
function will do when it is completed. (Normally you
don't write documentation to tell what a stub function does.)
- In the level-two program you need to finish the code for the
main function and all the level-two functions.
- In the level-two program you need to have stubs for all the
level-three functions.
- If you follow my suggested design the main program will have
some declarations of variables, perhaps some function
prototypes, perhaps an initial call to askPermission, and a
loop containing calls to getParams, getImage, doTileJob, and
askPermission.
- In your level-two program you can probably put versions of
askPermission, and getParams that don't make calls to any
level-three functions (except 'built-in' functions that you
don't need to write).
- Depending on how you want to design the program, you may want
getImage to call a level-three function that you write. On the
other hand you may not want to do that.
- I think doTileJob really has to call a level-three function to
do most of the work. I think doTileJob is bound to be too long
and 'busy' if you try to write it without a lot of reliance on
a level-three function.
- getImage and doTileJob are both functions that could be written
with the basic structure of a for-loop.
- getImage can begin by
- getting the height and width of the image,
- setting up to begin reading on the first character of
the next line, and
- then performing a loop: "For each row index i from 0
to heightOfFileImage-1 get the characters in the next
line in the image file and put them in row i of the
buffer array."
The function that puts the next line of the file into the
buffer can be a stub in your level-two program. You can
put off figuring out how to do that part of the problem
until you start work on the level three program.
- The basic structure of doTileJob could be "For each row
index i from 0 to numberOfRowsInTheTiling, make a row of
numberOfColumnsInTheTiling 'tiles' across the standard
input (you have to do it by copying characters out of the
buffer array). The function that makes the row of tiles
can be a stub in your level-two program. You can put off
figuring out how to do that part of the problem until you
start work on the level three program.