21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

122 Chapter 10 ■ Data structure design<br />

will need statements to print a heading, print a transaction line and so on. But we can<br />

also see that we will need:<br />

■ a loop to print a number of pages<br />

■ a loop to print the set of transaction lines on each page.<br />

You can see that this description of the program structure matches the structure of<br />

the report. What we have done is to derive the structure of the program from what we<br />

know about the structure of the report.<br />

These small examples show how it is possible to approach program design using the<br />

structure of data. We will return to these examples later, showing exactly how the<br />

method treats them.<br />

10.2 ● A simple example<br />

Let us consider the design of a program to display the following pattern on a computer<br />

screen. We will assume that, in drawing this pattern, the only possible cursor<br />

movements are across the screen from left to right, and down to the beginning of a<br />

new line.<br />

*<br />

***<br />

*****<br />

*****<br />

***<br />

*<br />

The first step in the method is to analyze and describe the structure of the in<strong>for</strong>mation<br />

that the program is to create. The product of this step is called a data structure<br />

diagram. The diagram <strong>for</strong> the pattern is given in Figure 10.1.<br />

Top half<br />

Picture<br />

Middle<br />

Bottom<br />

half<br />

* *<br />

Line Line<br />

Figure 10.1 Data structure diagram <strong>for</strong> the asterisks pattern

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

Saved successfully!

Ooh no, something went wrong!