computer science: a structured programming approach using c1 4-6 scope scope determines the region...

Post on 03-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Computer Science: A Structured Programming Approach Using C 1

4-6 Scope

Scope determines the region of the program in which a Scope determines the region of the program in which a defined object is visible. Scope pertains to any object defined object is visible. Scope pertains to any object that can be declared, such as a variable orthat can be declared, such as a variable ora function declaration. a function declaration.

Global ScopeLocal Scope

Topics discussed in this section:Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C 2

FIGURE 4-32 Scope for Global and Block Areas

Computer Science: A Structured Programming Approach Using C 3

Variables are in scope from declaration until the end of their block.

NoteNote

Computer Science: A Structured Programming Approach Using C 4

It is poor programming style to reuse identifiers within the same scope.

NoteNote

Computer Science: A Structured Programming Approach Using C 5

4-7 Programming Example— Incremental Development

Top–down development, a concept inherent to Top–down development, a concept inherent to modular programming, allows us to develop programs modular programming, allows us to develop programs incrementally. By writing and debugging each incrementally. By writing and debugging each function separately, we are able to solve the program function separately, we are able to solve the program in smaller steps, making the whole process easier.in smaller steps, making the whole process easier.

First Increment: main and getDataSecond Increment: addFinal Increment: Print ResultsThe

Topics discussed in this section:Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C 6

FIGURE 4-33 Calculator Program Design

Computer Science: A Structured Programming Approach Using C 7

PROGRAM 4-13 Calculator Program—First Increment

Computer Science: A Structured Programming Approach Using C 8

PROGRAM 4-13 Calculator Program—First Increment

Computer Science: A Structured Programming Approach Using C 9

PROGRAM 4-13 Calculator Program—First Increment

Computer Science: A Structured Programming Approach Using C 10

PROGRAM 4-14 Calculator Program—Second Increment

Computer Science: A Structured Programming Approach Using C 11

PROGRAM 4-14 Calculator Program—Second Increment

Computer Science: A Structured Programming Approach Using C 12

PROGRAM 4-14 Calculator Program—Second Increment

Computer Science: A Structured Programming Approach Using C 13

PROGRAM 4-14 Calculator Program—Second Increment

Computer Science: A Structured Programming Approach Using C 14

PROGRAM 4-15 Calculator Program—Final Increment

Computer Science: A Structured Programming Approach Using C 15

PROGRAM 4-15 Calculator Program—Final Increment

Computer Science: A Structured Programming Approach Using C 16

PROGRAM 4-15 Calculator Program—Final Increment

Computer Science: A Structured Programming Approach Using C 17

PROGRAM 4-15 Calculator Program—Final Increment

Computer Science: A Structured Programming Approach Using C 18

4-8 Software Engineering

In this section we discuss three different but related In this section we discuss three different but related aspects of software engineering design: the structure aspects of software engineering design: the structure chart, functional cohesion, and top–down development.chart, functional cohesion, and top–down development.

Structure ChartsStructure Chart RulesFunctional CohesionTop–Down Development

Topics discussed in this section:Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C 19

FIGURE 4-34 Structure Chart Symbols

Computer Science: A Structured Programming Approach Using C 20

FIGURE 4-35 Structure Chart Design

Computer Science: A Structured Programming Approach Using C 21

Structure charts show only function flow; they contain no code.

NoteNote

Computer Science: A Structured Programming Approach Using C 22

FIGURE 4-36 Common Functions in a Structure Chart

Computer Science: A Structured Programming Approach Using C 23

Table 4-1 Structure Chart Rules

Computer Science: A Structured Programming Approach Using C 24

FIGURE 4-37 Calculate Taxes Design

Computer Science: A Structured Programming Approach Using C 25

FIGURE 4-38 Design For Print Report

Computer Science: A Structured Programming Approach Using C 26

PROGRAM 4-16 Top–down Development Example

Computer Science: A Structured Programming Approach Using C 27

PROGRAM 4-16 Top–down Development Example

Computer Science: A Structured Programming Approach Using C 28

PROGRAM 4-16 Top–down Development Example

top related