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

  the answer to everything in the universe

  NOT the same as python code

  a formal computer language

  a type of code that hackers use

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

  as artistic as possible, ambiguous and suitably vague

  creative, polite and similar, when possible, to one particular language preferrably C++ or Java

  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

  Delete all the IF statements

  It cannot be improved

  The data types of the inputs could be specified

  Put variables in UPPER CASE

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

  None of the above

  Input the dimensions of a rectangle and print the breadth

  Input the dimensions of a rectangle and print its area.

  Input the length and breadth and display length

 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 bigab

  None of the above

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

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

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

  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

 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

  if name is

  for smith = 0 to 10

  while smith = 1

  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 (a = b = c)

  if 3 = equal

  if 1,2,3 = equal

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

 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:

  Language independent

  in any language except English

  Language dependent

  Language specific