Transcript
Page 1: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

CHAPTER 2:MODULARIZATION

Page 2: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 3: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 4: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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.

Page 5: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Chapter 3

5

Printer Spacing Chart

Page 6: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

6

Printer Spacing Chart with Title and Column Headings

Page 7: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 8: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Completing Documentation

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

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

Page 9: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 10: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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”

Page 11: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Chapter 3

11

Modularized Logic from a Payroll Program

Page 12: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 13: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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. . .

Page 14: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 15: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 16: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 17: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Understanding the Mainline Logic for Many Procedural Programs (continued)

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

Page 18: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

18

An Organizational Hierarchy Chart

Page 19: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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

Page 20: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Example of local variable

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

Page 21: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

Example of global variable

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

Page 22: CHAPTER 2: MODULARIZATION. Objectives  Understanding Documentation  Learn about documentation  Learn about the advantages of modularization  Learn

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


Top Related