0% found this document useful (0 votes)
25 views

Flowcharts and Pseudocode Lesson Three

Uploaded by

Seraya MONGBE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Flowcharts and Pseudocode Lesson Three

Uploaded by

Seraya MONGBE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 49

Flowcharts and Pseudocode

Lesson Three
Learning Objective
• To design, use and evaluate computational abstractions that model the state and
behaviour of real-world problems and physical systems.

Success Criteria
• To perform an algorithm trace.
• To use inputs and outputs in flowcharts.
• To use Flowgorithm to build and test flowchart algorithms.
High-Low Hedgehogs
Flo the hedgehog likes to play a game with her friend Sue.

You may have played this game yourself. This is how it goes:
• Flo thinks of a number between 1 and 100.
• Sue then tries to guess what the number is.
• If Sue’s guess is too low, then Flo will answer: “too low, guess again”.
(No surprises there!)
• If Sue’s guess is too high, then Flo will answer: “too high, guess again”.
• If Sue’s guess is correct, then Flo will answer: “that’s right!”
• Then Sue thinks of a number between 1 and 100 and Flo has to guess.

Let’s see how this works…

Next
High-Low Hedgehogs
OK so I’ve thought of a number…

Is it 50?

Too low, try again.

Is it 75?

Too high, try again.

Is it 63?

That’s right! Your turn Sue…

Now it’s your turn – try this game in pairs.


High-Low Hedgehogs
Now you know the rules, your challenge is to create a flowchart that describes the High-
Low Hedgehogs game.

Start your flowchart like this and then complete it.

Start

Person 1: Pick a number between 1 and 100

Person 2: Make a guess


High-Low Hedgehogs
Start

Person 1: Pick a number between 1 and 100

Person 2: Make a guess

Person 1 picks the number 78


Is this the best way to
Person 2 makes the guess: 30 draw a flowchart for
this game?
Person 1 says: too low Can you think of a
better way?
Person 2 makes the guess: 95

Person 1 says: too high

… and so on …
High-Low Hedgehogs
Here’s a better answer. Why is this a better flowchart?

Start

Person 1: Pick a number between 1 and 100

Person 2: Make a guess


Ye
Is guess too low? s Too low – try again.

No Ye
Is guess too high? s Too high – try again.
No
That’s right!

Stop
Algorithm Tracing
Sometimes it’s useful to do an Algorithm Trace. This means stepping through the
algorithm (in this case our flowchart) one step at a time.
Let’s imagine that Person 1 picks the number 26….

Start

Person 1: Picks the number 26


Algorithm Tracing
Person 2 then guesses 12…

Start

Person 1: Picks the number 26

Person 2: Makes a guess of 12


Algorithm Tracing
12 is lower than 26, so the result is ‘Too low – try again.’
Follow the flowlines of the flowchart, and Person 2 has another guess…

Start

Person 1: Picks the number 26

Person 2: Makes a guess of 12


Ye
Is guess too low? s Too low – try again.

No
Algorithm Tracing
Person 2 now makes a guess of 34.
34 is higher than 26 so this time the result is ‘Too high – try again.’

Start

Person 1: Picks the number 26

Person 2: Makes a guess of 34


Ye
Is guess too low? s

Ye
Is guess too high? s Too high – try again.
Algorithm Tracing
Finally, Person 2 gets lucky and guesses 26.
26 is not lower or higher than 26 so the result is ‘That’s right!’ and the game
is over.

Start

Person 1: Picks the number 26

Person 2: Makes a guess of 26


Ye
Is guess too low? s

No
Ye
Is guess too high? s Too high – try again.
No
That’s right!

Stop
Inputs and Outputs
We can improve our flowchart even further by using inputs and outputs.

Keywords
An input is information (data) that we put into an algorithm.
An output is information that we get out of the algorithm.

Here’s the flowchart symbol for an input or output:

This shape is a
Input / Output parallelogram.
Inputs and Outputs
Let’s add these input and output boxes to
Start our High-Low Hedgehog flowchart:

Person 1: Picks a number from 1 to 100

Person 2: Makes a guess


Ye
Is guess too low? s Too low – try again.
No
Ye
Is guess too high? s Too high – try again.
No
That’s right!
This doesn’t look
much different!
Stop
Flowgorithm
• Time to put our skills and knowledge into action.

• We have already seen how we can draw flowcharts


on our computers, for example: https://www.draw.io/

• Flowgorithm is an excellent resource


that can help us to design flowcharts.

You can download it at home for free.

• What makes Flowgorithm particularly


useful is that we can use it to test our
flowcharts.
It will even turn flowcharts into
pseudocode.
Flowgorithm

We’ll start by creating together


this flowchart in
Flowgorithm:
Flowgorithm
Step one:

Click on the flowline


between the Main and End
terminators.

This will open a menu as shown


here.

In the menu, click on the Declare


box.
Flowgorithm
Step two:

You should be able to see your


new Declare box.

Double-click on the Declare box


to open this Declare Properties
window:

Under Variable Name: type in


the word age as shown here.

Then press OK.


Flowgorithm
Step three:

Here we can see age. In our


flowchart, age is a variable. We’ll
find out what variables are next
lesson.

Next, click on the flowline


underneath age.

This will open the menu. In the


menu click on the Input box.
Flowgorithm
Step four:

Your new Input box will magically


appear underneath age:

Double-click on the Input box.


Flowgorithm
Step four:

The Input Properties window will open like this:

Once again, type in the word


age in this box.

Then click the OK button.


Flowgorithm
Step five:

Here is our new Input box.

Next, click on the flowline underneath


the Input box:
Flowgorithm
Step five:

The menu will open again:

Click on the If box. Remember: this


is a flowchart decision box.
Flowgorithm
Step six:

This is what our flowchart now looks like:

We’re nearly there!

Click on the False flowline as shown here:


Flowgorithm
Step six:

From the menu:

Click on the Output box:


Flowgorithm
Step six:

Double-click on our new


Output box:
Flowgorithm
Step six:

The Output Properties


window will open.

In this box type the words: “You are


too young to vote.” Note: make sure
to include the “quotation marks”.

Click on OK.
Flowgorithm
Step seven:

Now do the same for the True


flowline.

On this side enter the text “You can


vote.”
Flowgorithm
Step eight:

Finally …
Double-click on the If box:

Then in the
If Properties window type:

age > 18

Click OK.
Flowgorithm

Well done. Your first Flowgorithm


flowchart.

Now it starts to get interesting…

First of all, let’s find out how


Flowgorithm can convert
a flowchart into pseudocode…
Source Code

Click on the Tools menu at the


top of the Flowgorithm window:

Then click on Source Code Viewer…


Source Code
The Source Code Viewer will convert
flowcharts into a range of different
programming languages.

Click here and try changing the language.

For pseudocode, select the Gaddis


Pseudocode option.

This is a very useful feature. If you


choose to study Computer Science I can understand this!
at GCSE level and beyond, this feature
will save you hours of time and effort.
Source Code

Here’s our algorithm in the Python


programming language:
Source Code

Here’s our algorithm in the


Javascript programming language:
Testing Flowcharts

Converting flowcharts into pseudocode


and other programming languages is a
very useful feature of Flowgorithm.

Flowgorithm can also help us with


testing our flowcharts.

Let’s find out how to test and run our


Voting Age flowchart…

Next
Testing Flowcharts
Click on the green triangular Play button at the top of the Flowgorithm window:

Click on the green triangular Play


button at the top of the Flowgorithm
window:

This will open the Console window.

The Console asks us to enter a value for


age:
Testing Flowcharts
Enter your age into the box as shown here:

Click the Enter button. Watch what happens …


Testing Flowcharts

Flowgorithm now runs your flowchart.

Here’s the age you entered:

Here’s the output:

Was the output what you expected?


Testing Flowcharts

Click the green Play button again to run


your flowchart.

Try entering a different age this time.

What was the output this time?

Test your flowchart with different ages.


Testing Flowcharts
Time to put our skills and knowledge into action.
Help!
Flo needs your help once again!

Flo needs to eat at least 10 yummy snails every day to


stay healthy. She has started to make a Flowgorithm
flowchart to help her work out if she has eaten enough
snails or not.

She has almost finished her flowchart but she doesn’t


know what to put inside the decision box.

In Flowgorithm, copy her flowchart (you will see it


soon) and then complete the If decision box. Test and
run your flowchart afterwards.
Healthy Hedgehog
What goes
in here?
Healthy Hedgehog
Here’s the best answer:

snails >= 10 means:


IF the number of snails is greater than or equal to 10 THEN …
Healthy Hedgehog

Here’s the best answer:

This is the second


best answer.
How is snails > 10 different to snails >=
10?
Will it produce a different result?
Healthy Hedgehog
Flo’s completed flowchart:
Healthy Hedgehog
Testing the flowchart, if Flo eats 7 yummy snails today then:

I’m starving!

Further challenge: can you find the pseudocode for this flowchart?
Let’s Bring It All Together
Keywords
Stepping through an algorithm one step at a time and looking at inputs,
values and outputs is called an Algorithm Trace or Dry Running.

Keywords
An input is information (data) that we put into an algorithm.
An output is information that we get out of the algorithm.

Pause for Thought


Do you think that testing algorithms is a waste of time?
A huge amount of public money has been spent on computer
systems that have not been tested properly and then failed.
A quick search on the internet will show you many such situations.
This is YOUR money that has been wasted!
Do you still think that testing is a waste of time?
Learning Objective
Green Light: you feel fully confident with this objective and you understand it well.
Amber Light: you have understood most of the objective and you are happy with
your progress.
Red Light: you have understood some of the objective and you will think about it some more
later on, perhaps asking a friend or teacher for help.

Success Criteria
• To know how to perform an algorithm trace.
• To use inputs and outputs in flowcharts.
• To use Flowgorithm to build and test flowchart algorithms.
Nailing It Down
Flowgorithm is a very useful program.

You can download Flowgorithm for free at


this URL: http://www.flowgorithm.org/

Try downloading Flowgorithm at home and


try out the Example Programs:

You might also like