Pseudocode and Flow Charts
Pseudocode and Flow Charts
Terminology tip
A computer program may also be called:
Project Application Solution
Program Planning
A recipe is a good example of a plan Ingredients and amounts are determined by what you want to bake Ingredients are input The way you combine them is the processing What is baked is the output
Chapter 2 - VB.NET by Schneider 8
10
Algorithms
A step by step series of instructions for solving a problem (a recipe is an example of an algorithm)
13
14
Algorithm
1. Request the number of sheets of paper; call it Sheets. (input) 2. Divide Sheets by 5. (processing) 3. Round the quotient up to the next highest whole number; call it Stamps. (processing) 4. Reply with the number Stamps. (output)
Chapter 2 - VB.NET by Schneider 15
Flowcharts
Graphically depict the logical steps to carry out a task and show how the steps relate to each other.
16
Flowchart symbols
17
18
Flowchart example
19
Pseudocode
Uses English-like phrases with some VB.NET terms to outline the task.
20
Pseudocode example
Determine the proper number of stamps for a letter Read Sheets (input) Set the number of stamps to Sheets / 5 (processing) Round the number of stamps up to the next whole number (processing) Display the number of stamps (output)
Chapter 2 - VB.NET by Schneider 21
Hierarchy charts
Show how the different parts of a program relate to each other Hierarchy charts may also be called structure charts HIPO (Hierarchy plus Input-Process-Output) charts top-down charts VTOC (Visual Table of Contents) charts
Chapter 2 - VB.NET by Schneider 22
23
Divide-and-conquer method
Used in problem solving take a large problem and break it into smaller problems solving the small ones first Breaks a problem down into modules
24
Statement structure
Sequence follow instructions from one line to the next without skipping over any lines Decision - if the answer to a question is Yes then one group of instructions is executed. If the answer is No, then another is executed Looping a series of instructions are executed over and over
25
26
27
28
Flowchart
30
Pseudocode
Program: Determine the direction of a numbered NYC street Get street If street is even Then Display Eastbound Else Display Westbound End If
Chapter 2 - VB.NET by Schneider 31
Hierarchy Chart
32
Flowchart
34
Pseudocode
Program: Determine the average grade of a class Initialize Counter and Sum to 0 Do While there are more data Get the next Grade Add the Grade to the Sum Increment the Counter Loop Computer Average = Sum/Counter Display Average
Chapter 2 - VB.NET by Schneider 35
Hierarchy Chart
36
Comments
When tracing a flow chart, start at the start symbol and follow the flow lines to the end symbol Testing an algorithm at the flow chart stage is known as desk checking Flowcharts, pseudocode, and hierarchy charts are program planning tools that are not dependent on the programming language being used
Chapter 2 - VB.NET by Schneider 37
Comments continued
There are four primary logical programming constructs sequence decision loop unconditional branch
38
Unconditional branch
Appear in some languages as Goto statements Involves jumping from one place in a program to another Structured programming uses the sequence, decision, and loop but forbids unconditional branch
Chapter 2 - VB.NET by Schneider 39
42