chapter 2: modularization. objectives understanding documentation learn about documentation learn...

Post on 15-Dec-2015

246 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CHAPTER 2:MODULARIZATION

Objectives Understanding Documentation Learn about documentation Learn about the advantages of

modularization Learn how to modularize a program Declare local and global variables and

constants Create hierarchy charts

Documentation

Documentation Documentation refers all supporting material that goes

with a program Two major categories: for users and for programmers

User Documentation: End users (people who use computer programs)

Program Documentation falls into two categories: Internal program documentation include comments

within code External program documentation include supporting

paperwork written before programming begins

Output Documentation

Figure 3-2 Inventory records displayed in a GUI environment

Figure 3-3 Inventory records displayed in a running program

Output documentation is usually the first to be written. user who requested output generally present to programmer with an example.

Chapter 3

5

Printer Spacing Chart

6

Printer Spacing Chart with Title and Column Headings

Input Documentation

Describes what input is available to produce the output

File description: Describes data stored in a file Indicates fields, data types, and lengths

Completing Documentation

• Program documentation may contain:– Output design– Input description– Flowcharts– Pseudocode– Program code listing

• User documentation may contain:– Manuals– Instructional material– Operating instructions

Modularization

Modularization: breaking a large program into modules

Advantages of modularization: Provides abstraction Allows multiple programmers to work

simultaneously Allows code reuse Makes identifying structures easier

Chapter 3

10

Modularizing a Program- Flowchart Symbols

Sentinel Symbols A module has it own

sentinel symbols (Start and End)

The Start symbol has the name of the module

The End symbol has the word “RETURN”

Chapter 3

11

Modularized Logic from a Payroll Program

Modularization Provides Abstraction

Focuses on important properties while ignoring non-essential details

Avoids low-level details Makes complex tasks look simple High-level programming languages allow

English-like vocabulary One statement corresponds to dozens of

machine instructions Modules provide another way to achieve

abstraction

Modularization Provides Abstraction (continued)

To-do list with abstraction

Do laundryCall Aunt NanStart term paper

To-do list without abstraction

Pick up laundry basketPut laundry basket in car

Drive to laundromatGet out of car with basket

Walk into laundromatSet basket down. . .

Modularization Allows Multiple Programmers to Work on a Problem

Commercial programs rarely written by a single programmer

Development time is significantly reduced

Large programming projects can be divided into modules

Modules can be written by different programmers or programming teams

Modularization Allows You to Reuse Your Work

Subroutines that are useful should be used more than once in a program Example: routine that checks the current date

Instructions placed in their own module are easy to port to other applications

Reusability: the ability to use modules in a variety of applications

Reliability: assurance that a module has been tested and proven to function correctly

Reliable software saves times and money

Understanding the Mainline Logic for Many Procedural Programs

Mainline logic of most procedural programs follows same general structure: Housekeeping tasks

Variable and constant declarations Opening files

Main loop tasks Processes that must occur for every data record

End-of-job tasks Print footer lines Close open files

Understanding the Mainline Logic for Many Procedural Programs (continued)

Figure 3-16 Flowchart and pseudocode of mainline logic for a typical procedural program

18

An Organizational Hierarchy Chart

Local and global variable

LocalThese variables only exist inside the specific function that creates them. They are unknown to other functions and to the main program. scope is limited to that function.

GlobalThese variables can be accessed (ie known) by any function comprising the program

Example of local variable

main() { int i=4; i++;}

Example of global variable

int i=4; main() { i++; }

int i=4; /* Global definition */ main() { i++; /* global variable */ func } func() { int i=10; /* Internal declaration */ i++; /* Internal variable */ }

top related