Preview

18 -Pseudocode and Flow Diagrams

 1. Many students find the writing of pseudo-code and creating flow diagrams to solve problems quite challenging. First things first, fill in the blanks for the following important definitions.
_______ the series of steps to solve a problem or perform an action.

_______ a diagram that shows the inputs, outputs and processes in an 
algorithm.

_______ an action that takes place.

______  simplified programming code that is not language specific, 
used to design algorithms. (for example it could resemble plain 
english.)

*It lets the programmer focus on the _____, rather than the syntax 
of the problem.

  Algorithm / FlowChart / Process / Pseudocode / logic

  Pseudocode / Algorithm / FlowChart / Process / coding

  Process / FlowChart / Algorithm, / Pseudocode /coding

  Process / Pseudocode /Algorithm / FlowChart /logic

 2. The following diagram shows some typical flow chart symbols. Which two are the wrong way round? (i.e need to be swapped in order to be in the right symbol/shape to match the text)
uploads/flowchart.png

  Start/End and Input/Output

  Process and Decision

  Decision and Start/End

  Decision and Input/Output

 3. The paragraph below provides a more detailed description of a flow chart. Fill in the blanks.
A flowchart can be used to represent an _________
It shows the data that is input, and output.
It shows the processes (_______) that take place.
It shows the _________ and repetitions that take place.
______ are used to show the flow of control. 
Set _______ are used to represent different functions.

  algorithm / actions / variables / shapes / code snippets

  algorithm / actions / variables / shapes / lines

  algorithm / variables / decisions / shapes / lines

  algorithm / actions / decisions / lines / shapes

 4. 1) What will be the result if 2 and then 4 are input? 2) What will be the result if 5 and 8 are input?
uploads/flowchart2.png

  1) True 2) False

  1) 13 2) 8

  1) 8 2) 13

  1) 6 2) 13

 5. Fill in the blanks below for the paragraph on pseudocode.
Pseudocode literally means ______ code

It is part way between English sentences, and programming code

It is language __________ (it can be read by programmers who are able
to use any language)

It allows programmers to focus on the logic of the problem rather than worrying
about the _________ of a specific language

  good / specific / variables

  Pretty / neutral / syntax

  Fake / neutral / syntax

  Functional / specific / variables

 6. There is no specific convention for writing pseudocode but it is important that it can be understood by fellow programmers (and it should not be language dependent). It should also be accurate. Can you spot any omissions below?
EXAMPLE 1: #pseudocode that python programmers may use
height = input("Enter the height")
width = input("Enter the width")
area = (height * width)
print (area)

EXAMPLE 2: #pseudocode that vb.net /javascript etc programmers may use
var height, width, area as INT <-- note in VB.Net variables declared seperately
height=INPUT("Enter the height")
width =INPUT("Enter the width")
area=(height*width)
print(area)

  Example 2 declares the variables first which should never be done

  Example 2 uses capital letters for INPUT which should never be used in pseudocode

  Example 1 doesn't use capital letters for INPUT which is important

  Example 1 doesn't specify the data types of the variables which is important

 7. 'Nile' - a new delivery company lets customers track their parcels. To track a parcel a customer enters an 8 digit parcel number. Fill in the blanks for the pseudocode below that checks to see if the parcel number is valid.
#Task: Write pseuodocode to ask a user for their parcel number, output VALID
if there are eight characters, output INVALID, if there are not eight characters.

parcelnumber=input("Enter parcel number:") #parcelnumber = string
____________________________________________?
print("VALID")
else
	print("INVALID")

#Fill in the blanks for line 5

  if parcelnumber(slice:chararacter:0/1/1%)% - ://parse

  if parcelnumber has 8 characters THEN

  if parcelnumber====8:

  if parcelnumber <8 characters THEN

 8. For the below python code example, pseudocode is shown. Making the for loop easy to understand for all programmers (not just python coders) is important. For example 'range' is not used in all languages. What could be improved?
#PSEUDOCODE 

n = input("Enter a number")
for x in range(n)
	print x
next x

  Line 4 could be: for x = 0 to n (specifying the start and stop) and line 1: integer input

  Line 4 could be: loop through starting at 0 and stopping at n.

  Line 6 could be changed to: "please go to the next value of x now"

  Line 3 could be changed to: n = input("Enter n")

 9. A program asks the user to input a whole number. Analyse the pseudocode below and predict what this program does if a decimal number is entered instead of a whole number.
do
	number = input("Enter a whole number")
	check = number MOD 2
	if check == 1 then
		print("This is a whole number")
		wholeNumber = true
	elseif check == 0 then
		print("This is a whole number")
		wholeNumber = true
	else
		print("This is NOT a whole number, try again!")
	endif

until wholeNumber == true

  the pseudocode's logic is wrong, so it would say: "This is a whole number"

  it would print "false", as the input is not a whole number

  it simply tells them their input is invalid and exits the program

  it simply tells them their input is invalid and asks for the input again.

 10. The following algorithm which has been written to describe the movement of a robotic car. Is it pseudocode, a flowchart or actual programming language code?
set 'stop' to False
repeat
if there is an obstacle 
	set 'stop' to True
otherwise
	move forward 1 cm
until 'stop' is True

  flowchart

  none of these options apply, as this isn't an algorithm at all.

  pseudocode

  python code