Understanding Top-Down Design and Modular Programming Concepts
130 likes | 289 Vues
This comprehensive review of top-down design principles outlines the importance of breaking programs into smaller, manageable modules. Each module should be self-contained and perform specific tasks, while creating clear hierarchies and flowcharts to visualize the structure. Key programming concepts such as control structures, operators, loops, and error checking are explored in depth. Additionally, it highlights defensive programming techniques to avoid common pitfalls like division by zero, and methods for implementing efficient data validation. This guide serves as a foundational resource for aspiring programmers.
Understanding Top-Down Design and Modular Programming Concepts
E N D
Presentation Transcript
Test 2 review Tiffany Barnes 3/15/07
Top-down design • Break a program into parts=modules • Draw a picture/hierarchy chart • Fill in parts with pseudocode • If modules are complex, repeat the process for each module
Modules • Self-contained, compact, performs a single task • Part of a program • Calling a module • Transfers control to the first line of the module • When it is complete, it returns to the statement right after the call
Example • Problem: write a program that computes the avg. of three #s entered by the user • Parts • Display welcome message • Input data • Calculate Average • Output results
Testing • Check for syntax & logic errors • Syntax errors • Violations of prog. language’s rules for statement structure • Logic errors • Failing to carry out the given task
Flowcharts • Terminators (rounded box) • Process (Box) • I/O (parallelogram) • Decision (diamond) • Connector
Control structures • Sequential (in sequence) • Loop (repetition) • Branch to previous step • Decision (selection) • Branch forward, causes some code to be skipped
Operators • Arithmetic • +,-,*,/ • Logical • Not, And, Or • Relational: =, !=, <, >, <=, >= • Order: Arithmetic, relational, logical
Defensive programming • Avoid division by zero • Avoid sqrt of neg number
Loops • Pre-test: while • Test the condition before the lopp • Post-test: do-while • Test the stopping condition after the loop
Loop control • Sentinel-value • Counter-controlled loops • Built-in: For • Can implement with a while loop
Loop uses • Gathering input • Data validation • Computing sums and averages • Running total
Nested loops • When one loop is inside another