Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.

Similar presentations


Presentation on theme: "Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating."— Presentation transcript:

1 Problem Solving Chapter 2

2 What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating

3 What does a programmer do? n Understand the problem specification n Develop a detailed logical plan (algorithm) for solving the problem at hand n Translate the algorithm into a programming language n Create test data to determine the correctness of their algorithm/program n Test & debug the algorithm/program n Document the program

4 Levels of algorithm development n Global - hierarchy diagram n Local - flowchart n Whatever you do…you MUST… RESIST THE URGE TO CODE!!!

5 Structured program design n Also called top-down or modular programming n Idea is: –sketch a global, modular solution hierarchy diagram or pseudocode –refine each module independently flowcharts or pseudocode n There are many advantages to this approach

6 In Visual Basic (or any language that supports building GUI’s) n An event procedure (or any user- defined procedure) is a module. n In development, the programmer’s focus is the GUI - its design drives all programming decisions & design

7 A well-written program is... n Modular (structured) n Well-designed (good algorithm) n Easy to follow –code is “clean” –simple –uses meaningful names & symbols –documented

8 Global design n Hierarchy diagrams

9 Local design - flowcharts Start/Stop block Processing block Decision block Input/Output block

10 Logical constructs n There are just three logical constructs used in well-designed flowcharts & structured programs: –sequence (Fig. 2.1, p. 36) –selection (Fig. 2.3-2.5, p. 38-40) –iteration (Fig. 2.7-2.8, p. 40-41)

11 Sequential execution n A series of I/O & processing blocks, with the flow of execution passing straight from the top (start block) to the bottom (stop block) - no twists or turns n Why is this limiting?

12 Conditional branching n The flow of execution takes different turns, on the basis of certain conditions being met… n What is a condition?

13 start stop Read x,y x > y? yesno Write y Write x

14 Three types of if statements... n If - then - else –Compare two numbers x & y and display the larger of the two. n Null else –If y <> 0, divide x by y and put the quotient in z (otherwise, do nothing at all) n Nested –Make further comparisons

15 The assignment statement variable = expression n variable is a symbolic name that represents a memory location n expression is any combination of variables and/or constants connected by arithmetic operators +,-,*,/,**,^

16 Let’s do some examples…….


Download ppt "Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating."

Similar presentations


Ads by Google