Introduction to flowcharts and algorithms
description
Transcript of Introduction to flowcharts and algorithms
Flowcharts and Algorithms
A brief overview NXT-G is a programming language designed to help students and adults alike easily and quickly become familiar with
programming.
The following exercise is designed to give you a quick introduction to programming as well as to understand your
quick grasp of programming ideas. Attached to “Pleo” images are questions. In the boxes, please write
your answers.
Pleo the Dinosaur Robot.
Figure 1: Image source: http://images.amazon.com/images/G/01/electronics/detail-page/B000RWEGCO-2-med.jpg
Imagine that Pleo is your personal pet dinosaur robot. Pleo understands GO, FORWARD, BACKWARD, TURN,
LEFT, RIGHT, FEET, and STOP. When you say “GO FORWARD 3 FEET”, Pleo goes forward 3 feet as Pleo understands
numbers. When you say “TURN LEFT”, Pleo turns left.
Problem 1:
When you say “GO HOME”, Pleo does not respond. WHY?
Problem 2:
Pleo is in my living room. We are expecting visitors and my mom would like me to clean the living room
and put Pleo in my bedroom. Pleo is heavy but good at following directions. Can you help me by giving
him directions to my bedroom?
Problem 3:
What will happen if when Pleo is in my living room, I give him directions “GO FORWARD 12 FEET”?
Problem 4: Living-room: A program:
The next day my mom says, “Your room is a mess, clean up your room.” And this goes on and on. Pleo
moves between the living room and dining room, and I get tired of giving him instructions. I looked up
the manual and found that I could teach Pleo new words and write a “program” in the language that he understands.
I have to be careful, for the language Pleo understands is more than words, there is a specific rule to put the words
together.
How can I write “Living-room” a program that contains a series of instructions to move Pleo from my bedroom to the
living room?
The above exercises present a logical flow of sequence or instructions that a program, or in this case, a robot should
follow. The steps as written represent an algorithm, which closely resembles the English language.
Than
Color of
the ball
Is False
True
Introduction to flowcharts
A flowchart is a graphical representation of an algorithm. A flowchart shows the sequential flow of process a
program, or in this case, a robot should follow. Flowcharts play a vital role in the programming of a problem and are
quite helpful in understanding the logic of complicated and lengthy problems. Flowcharts support the programming
of an idea and are not specific to a given computer programing language. In addition, they are a quick and powerful
visual tool. Thus a flowchart is a preferred documentation of any program.
Flowcharts are usually drawn using some standard symbols; however,
Start or end of the program
Steps to be executed Input or output operation, used to refer to data and sensorial input Decision making and branching, is usually a true or false Connector or joining of two parts of program, especially useful in long programs
The accepted guidelines in flowcharting are:
a. Logical sequence should be followed.
b. The usual direction of the flow of a procedure or system is from left to right or top to bottom.
c. Only one flow line should go into and come out from a process symbol, connector, or input/output.
or
e. Only one flow line can enter a decision symbol, but
two or three flow lines, one for each possible answer,
should leave the decision symbol.
f. Only one flow line is used in conjunction with terminal
symbol.
Examples of flowchart
1. Move forward 10 steps
In this flowchart, what is the first action that our robot will do?
If the robot has completed 10 steps, what will the robot do?
2. Sort the ball by color
In this program, what will happen when the robot sees a red ball?
In this program, what will happen when the robot sees a green ball?
In this program, what will happen when the robot sees a blue ball?
What modification does your program need to sort the balls accurately?
What modification does your program need to sort the balls repeatedly?
Start Move forward
1 step Forward
10 steps? Stop
Yes
No
Start Is the ball
blue?
Yes
No
Read ball
color Store left
Store right
Repetition of a certain set of commands
The driver of the bus drives to a stop. At the stop he issues tickets to the passengers. Then the driver proceeds to the
next stop and repeats the process from the first to the last stop. The following flowchart shows how a set of
repeated conditions are contained within a set of commands.
Decision based on 2 or more criteria
Many programs draw decisions on multiple criteria which happen in parallel. A train can leave the station when all
passengers have boarded or the train has remained at the stop for 30 seconds. How can the given situation be
depicted in a flowchart?
The response can be summed up as an either/or algorithm:
Go to next station
If passengers have boarded or if train has stopped at the station for 30 seconds, move to next station.
Complete the instructions for this flowchart by:
Start
Go to next
stop
Passenger? Issue
ticket
Last stop
Yes
Yes
No No
Stop
Start ????????? Either/or
condition Stop
Yes
No
1. Setting up a timer input
2. Setting up the sensor input to check on the passengers.