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 

_______ an action that takes place.

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

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

  Process / Pseudocode /Algorithm / FlowChart /logic

  Process / FlowChart / Algorithm, / Pseudocode /coding

  Pseudocode / Algorithm / FlowChart / Process / coding

  Algorithm / FlowChart / Process / Pseudocode / 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)

  Decision and Input/Output

  Start/End and Input/Output

  Decision and Start/End

  Process and Decision

 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 / decisions / lines / shapes

  algorithm / variables / decisions / shapes / lines

  algorithm / actions / variables / shapes / code snippets

  algorithm / actions / variables / shapes / lines

 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?

  1) 8 2) 13

  1) 13 2) 8

  1) True 2) False

  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

  Functional / specific / variables

  Fake / neutral / syntax

  Pretty / neutral / syntax

  good / 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 /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")

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

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

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

  Example 2 declares the variables first which should never be done

 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

#Fill in the blanks for line 5

  if parcelnumber has 8 characters THEN

  if parcelnumber <8 characters THEN

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

  if parcelnumber====8:

 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?

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 3 could be changed to: n = input("Enter n")

  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"

 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.
	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
		print("This is NOT a whole number, try again!")

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
if there is an obstacle 
	set 'stop' to True
	move forward 1 cm
until 'stop' is True



  python code

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