flowcharts remember that a solution to a problem is called an algorithm. algorithms are often a...

11
Flowcharts • Remember that a solution to a problem is called an algorithm. • Algorithms are often a series of steps required to solve the problem. •A flowchart is a graphical representation of an algorithm. • Each step in the

Post on 21-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Flowcharts

• Remember that a solution to a problem is called an algorithm.

• Algorithms are often a series of

steps required to solve the problem.

• A flowchart is a graphical representation of an algorithm.

• Each step in the algorithm is represented by a different symbol

Page 2: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart
Page 3: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Used to indicate a predefined or user-defined function is called

Flowchart Symbols

Page 4: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Start

InputNumOne

InputNumThree

Input NumTwo

Calculate totalof 3 numbers

Output the total

Stop

Sequential StructureFlowchartExample

Create a program that will allow the user to input 3 integers and have the sum calculated and outputted.

Page 5: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Looping StructureFlowchart Example #1 – while loop

Create a program that will have the user input a name and have it outputted until the user wishes to finish.

Start

While:

Input a name

Input continue?

Output a name

True

False

Stop

Page 6: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Start

Initializetotal to 0

Initializei to 0

If i=10

Add numberto total

Incrementi

Stop

Input a number

No

Outputtotal

Yes

Looping StructureFlowchart Example #2 - for loopCreate a program that will allow the user to input 10 integers and have the sum calculated and outputted. Use a loop for this program.

Page 7: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Selective StructureFlowchart #1 - BinarySelection Structure

Create a program that will allow the user to input their age. If they are over 16, output they can drive, otherwise output they can’t drive.

Start

Input age

if age >=16True

Output“Drive”

Output“Can’t”

False

Stop

Page 8: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Selective StructureFlowchart #2 - Multiple Selection Structure

Create a program that will allow the user to input the number of widgets they sold. The program will output their level based on the following scale:

• Over 500, they are in the “Gold Club”

• Over 300, they are in the “Silver Club”

• Over 100, they are in the “Bronze Club”

• Not over 100, they are in the “Get a New Job Club”

Page 9: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

If sales >500

Start

Input sales

If sales >300

False

If sales>100

False

Output“New Job”

False

True

Output“Gold”

Stop

Output“Silver”

True

Output“Bronze”

True

Selective StructureFlowchart #2 Multiple Selection Structure (cont.)

Page 10: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Start

Input astring

Count Characters

In string

Count spaces

in string

Add 1 to numberof spaces

Calculate averagenumber of characters

in the words

Output average number

of words

Stop

Create a program that will allow the user to input a string of more than one word. It will calculate and output the average number of characters in the words.

Flowchart for a ProgramUsing PredefinedFunctions

Page 11: Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart

Flowchart Assignment Draw a flowchart for each of the following problems•Sequential #4•Selective #1, #3, #6•Repetitive #1b, #3b, #7•Functions #5, #6•Files #2