Preview

06 - Pseudocode

 1. Pseudocode is a text based way of setting out an algorithm. Pseudocode is not……
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

  all of the above are pretty much true

  the same as python code

  the answer to everything in the universe

 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

  as similar as possible to python programming code

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

  easy to read, consistent, unambiguous and error free

 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

  It cannot be improved

  The data types of the inputs could be specified

  Delete all the IF statements

  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 its area.

  Input the length and breadth and display length

  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 the letters a,b and c and output 'endif'

  Input the letters a,b and c and output bigab

  Input 3 numbers, and print the biggest.

  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

  Set sum to 0 and then display sum.

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

  Input 10 numbers, and print their total.

  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

  if name is "smith"

  for smith = 0 to 10

  name = smith

  while smith = 1

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

  if (a = b = c)

  if 1,2,3 = equal

  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:

  Language independent

  Language specific

  in any language except English

  Language dependent