< previous page page_421 next page >

Page 421
Lets not code these modules as functions but, instead, put each line of code into the level above. The resulting module structure chart consists of three levels rather than four.
Module Structure Chart:
Here is the module structure chart for the Transpose program. The chart emphasizes the importance of interface design. The arrows indicate which identifiers are received or returned by each module.
0421-01.gif
According to the structure chart, we have four modules to implement as C++ functions. In addition to main, let's name the functions PrintLast, FindLast, and PrintName. Before coding the problem, we should clearly spell out the function interfaces. Each interface mentions references to global variables (normally, only cin and cout).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
main: Calls PrintLast. No parameters are passed between main and PrintLast. Reads from cin and writes to cout.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
PrintLast: Is called by main. Calls FindLast and PrintName. Returns nothing to main (no formal parameters). Must obtain the first character of the last name from FindLast (actual parameter). Must pass the first character of the last name to PrintName (actual parameter).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
FindLast: Is called by $csPrintLast. Returns the first character of the last name to PrintLast (formal reference parameter). Reads from cin.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
PrintName: Is called by PrintLast. Receives the first character of the last name from PrintLast (formal value parameter). Reads from cin and writes to cout. Returns nothing.
This design is only one of many ways in which to structure the solution. In fact, it has some flaws. After presenting the C++ program, we discuss ways of improving the design.

 
< previous page page_421 next page >