130 likes | 273 Views
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
E N D
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