next up previous
Next: Your mission Up: CS1320 Homework 6 Previous: User interface

Top-down design

Mr. Surd begins by defining, for each of the commands to draw a shape, an associated ``command-processing function'' whose job it will be to prompt for the desired coordinates, etc., and then call another ``drawing'' function to actually draw the shape. For example, when the user enters the p command to draw a point, the program invokes doPoint() (one of Mr. Surd's command-processing functions), which prompts the user for the point's coordinates and the character to use and then invokes drawCharacter() (one of Mr. Surd's drawing functions) to draw the character.

Mr. Surd notices that there are two operations that need to be done in most of the command-processing functions, namely obtaining an integer in a specified range from the user and obtaining a character from the user, so he writes a ``helper function'' for each of these operations, calling them obtainInteger() and obtainCharacter().

Mr. Surd also decides to hide the details of how he implements the two-dimensional grid. That is, he defines three basic functions to operate on the grid -- one to draw a single character at specified coordinates (drawCharacter()), one to print the grid (printDrawing()), and one to erase everything in the grid, that is, put spaces in all positions of the grid (clearDrawing()). All his other functions will make use of these basic functions. He does this because he has thought of a clever way of implementing the two-dimensional grid using a one-dimensional array, but he recognizes that (1) his other functions will be easier to understand if written in terms of operations on the conceptual two-dimensional grid, and (2) if he later changes his mind about the clever implementation, he will only need to change the three basic functions.


next up previous
Next: Your mission Up: CS1320 Homework 6 Previous: User interface

1999-10-19