chapter 2: modularization. objectives understanding documentation learn about documentation learn...
Embed Size (px)
TRANSCRIPT
- Slide 1
CHAPTER 2: MODULARIZATION Slide 2 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 Slide 3 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 Slide 4 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. Slide 5 Chapter 3 5 Printer Spacing Chart Slide 6 6 Printer Spacing Chart with Title and Column Headings Slide 7 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 Slide 8 Completing Documentation Program documentation may contain: Output design Input description Flowcharts Pseudocode Program code listing User documentation may contain: Manuals Instructional material Operating instructions Slide 9 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 Slide 10 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 Slide 11 Chapter 3 11 Modularized Logic from a Payroll Program Slide 12 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 Slide 13 Modularization Provides Abstraction (continued) To-do list with abstraction Do laundry Call Aunt Nan Start term paper To-do list without abstraction Pick up laundry basket Put laundry basket in car Drive to laundromat Get out of car with basket Walk into laundromat Set basket down... Slide 14 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 Slide 15 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 Slide 16 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 Slide 17 Understanding the Mainline Logic for Many Procedural Programs (continued) Figure 3-16 Flowchart and pseudocode of mainline logic for a typical procedural program Slide 18 18 An Organizational Hierarchy Chart Slide 19 Local and global variable Local These 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. Global These variables can be accessed (ie known) by any function comprising the program Slide 20 Example of local variable main() { int i=4; i++; } Slide 21 Example of global variable int i=4; main() { i++; } Slide 22 int i=4; /* Global definition */ main() { i++; /* global variable */ func } func() { int i=10; /* Internal declaration */ i++; /* Internal variable */ }