Preview

06 - Pseudocode

 1. Pseudocode is a text based way of setting out an algorithm. Pseudocode is....
MAKING COFFEE
===============
1.START
2. Realise Coffee is superior to Tea
3.(Ignore teacups) and Fetch a Coffee mug
4. Boil some water
5. Put a spoon of instant coffee into mug
6. Poor water into mug
7. Stir
8. Add sugar (or sweetner)
9. END

  a formal computer language

  a type of code that hackers use

  the answer to everything in the universe

  NOT the same as python code

 2. Pseudocode can differ, as there are no hard and fast rules, but what is important is that it is…..

  as artistic as possible but suitably vague to allow for subjective interpretation

  creative and preferrably similar in syntax to either the Java or C++ language

  easy to read, consistent, unambiguous and error free

  as similar as possible to python programming code

 3. Pseudocode should also be precise. How could the following pseudocode be improved?
CardNumber ....
===============
   CardNumber=INPUT(“Please enter Card Number”)
   DO
      Pin=INPUT(“Please enter Pin”)
      IF Pin != CorrectPin 
         PRINT(“Wrong PIN”)
      END IF
   UNTIL Pin==CorrectPin
   Amount=INPUT(“How much money would you like?”)
   IF Amount <= CurrentBalence THEN
      DispenseCash(Amount)
      CurrentBalence = CurrentBalence - Amount
   ELSE
      PRINT(“Sorry, insufficient funds”)
   END IF
END

  The data types of the inputs could be specified

  It cannot be improved

  Put variables in UPPER CASE

  Delete all the IF statements

 4. What does the following pseudocode 'do' (or outline)
INPUT length, breadth
area = length * breadth
display area

  Input the length and breadth and display length

  None of the above

  Input the dimensions of a rectangle and print its area.

  Input the dimensions of a rectangle and print the breadth

 5. This pseudocode is an outline for the following:
INPUT a,b,c
if a>b
    bigab=a
else
    bigab=b
endif
if c>bigab
    display c
else
    display bigab
endif

  Input 3 numbers, and print the biggest.

  Input the letters a,b and c and output 'endif'

  Input the letters a,b and c and output bigab

  None of the above

 6. Describe what this pseudocode is outlining?
sum=0
for n=1 to 10
    input number
    sum=sum+number
endfor
display sum

  Input 10 numbers, and print their total.

  Set sum to 0 and then display sum.

  Input the sum = 0 and add it to number, which gives you the sum

  Input some numbers ("some" has been spelt wrong) and then output them

 7. In the following pseudocode, the objective is to Display the ages of everyone called "smith". What line of logic is missing from line 4?
open "fred" for input
		read name, age from "fred"
		while not end of file
			????????????????????????
				display age
			endif
			read name, age from "fred"
		endwhile
		close files

  for smith = 0 to 10

  while smith = 1

  if name is "smith"

  name = smith

 8. This pseudocode wants to do this: Input 3 numbers and print either an "all 3 equal" or a "not all equal" message. What is missing?
INPUT a,b,c
		????????????????????
			display "all 3 equal"
		else
			display "not all equal"
		endif

  if 1,2,3 = equal

  if (a=b) and (a=c)

  if (a = b = c)

  if 3 = equal

 9. The following video shows pseudocode for the Binary search. It is acceptable for pseudocode to be the same as python code.

  FALSE

  TRUE

 10. Pseudocode must be:

  in any language except English

  Language dependent

  Language specific

  Language independent