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

  the answer to everything in the universe

  all of the above are pretty much true

  the same as python code

  a formal computer language

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

  easy to read, consistent, unambiguous and error free

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

  as similar as possible to python programming code

  as artistic as possible, ambiguous and suitably vague

 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

  Put variables in UPPER CASE

  It cannot be improved

  The data types of the inputs could be specified

 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 dimensions of a rectangle and print the breadth

  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

  None of the above

  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.

 6. Describe what this pseudocode is outlining?
sum=0
for n=1 to 10
    input number
    sum=sum+number
endfor
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

  Set sum to 0 and then display sum.

  Input 10 numbers, and print their total.

 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"

  name = smith

  while smith = 1

  for smith = 0 to 10

 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 3 = equal

  if (a = b = c)

  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 specific

  Language dependent

  Language independent

  in any language except English