Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

Process header Process issue 10.4 Multiple input and output streams 129 Writing down operations, attaching them to the program structure diagram (not shown) and translating into pseudo-code, gives: open files read header record while not end of file do total = 0 read record while not end of batch do update total read record endwhile display total read header record endwhile close files Process file produce report Process batch produce total Process body Process record Process receipt Figure 10.10 Program structure diagram for processing batches Process trailer Thus we have seen that, where a program processes more than one file, the method is essentially unchanged – the important step is to see the correspondences between the file structures and hence derive a single compatible program structure. * * >

130 Chapter 10 ■ Data structure design 10.5 ● Structure clashes In a minority of problems, the two or more data structures involved cannot be mapped onto a single program structure. The method terms this a structure clash. It happens if we try to use the method to design a program to solve the following problem. Design a program that inputs records consisting of 80 character lines of words and spaces. The output is to be lines of 47 characters, with just one space between words. This problem looks innocuous enough, but it is more complex than it looks. (Have a go if you don’t agree!) A problem arises in trying to fit words from the input file neatly into lines in the output file. Figures 10.11 and 10.12 show the data structure diagrams for the input and output files. Superficially they look the same, but a line in the input file does not correspond to a line in the output file. The two structures are fundamentally irreconcilable and we cannot derive a single program structure. This situation is called a structure clash. Although it is difficult to derive a single program structure from the data structure diagrams, we can instead visualize two programs: ■ program 1, the breaker, that reads the input file, recognizes words and produces a file that consists just of words. ■ program 2, the builder, that takes the file of words created by program 1 and builds it into lines of the required width. We now have two programs together with a file that acts as an intermediary between the programs. Input file Figure 10.11 Data structure diagram for input file * Line Output file * Line Figure 10.12 Data structure diagram for output file

Process<br />

header<br />

Process<br />

issue<br />

10.4 Multiple input and output streams 129<br />

Writing down operations, attaching them to the program structure diagram (not<br />

shown) and translating into pseudo-code, gives:<br />

open files<br />

read header record<br />

while not end of file<br />

do<br />

total = 0<br />

read record<br />

while not end of batch<br />

do<br />

update total<br />

read record<br />

endwhile<br />

display total<br />

read header record<br />

endwhile<br />

close files<br />

Process file<br />

produce report<br />

Process batch<br />

produce total<br />

Process<br />

body<br />

Process<br />

record<br />

Process<br />

receipt<br />

Figure 10.10 Program structure diagram <strong>for</strong> processing batches<br />

Process<br />

trailer<br />

Thus we have seen that, where a program processes more than one file, the method<br />

is essentially unchanged – the important step is to see the correspondences between the<br />

file structures and hence derive a single compatible program structure.<br />

*<br />

*<br />

>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!