|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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). |
|
|
|
 |
|
|
|
|
main: Calls PrintLast. No parameters are passed between main and PrintLast. Reads from cin and writes to cout. |
|
|
|
 |
|
|
|
|
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). |
|
|
|
 |
|
|
|
|
FindLast: Is called by $csPrintLast. Returns the first character of the last name to PrintLast (formal reference parameter). Reads from cin. |
|
|
|
 |
|
|
|
|
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. |
|
|
|
|
|