Answering pseudo-code questions
Questions which require you to answer in pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding. or a programming languageA language used by a programmer to write a piece of software. are used to examine your ability to write algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. in logical ways. The examiner will check your answer to see that it meets the meets the requirements outlined in the questions, and to see if you have shown that you have a good understanding of how to structure code.
Things to remember when answering pseudo-code questions
- You do not need to memorise the Edexcel pseudo-code - you will be given a copy of it during the examination.
- You can use any version of pesudo-code that you are familiar with.
- You do not have to be completely accurate in your pseudo-code, but what you write does have to make sense.
- Do not worry if you feel you cannot complete all of the pseudo-code algorithm. Depending on the mark scheme, you may still gain some marks.
- Remember, there are many different ways to solve a problem, so there will be many alternative algorithms.
The following question has been taken from an Edexcel past paper. It reflects the type of question that may appear in an exam paper.
Example question
The HappyPetBox Company needs a program to validate customer identifierA name given to a part of a program, such as a variable, constant, function, procedure or module..
Valid customer identifiers are nine characters long, ending with three uppercase letters.
Here are four examples of valid customer identifiers.
- 836154JSA
- 579317NOY
- 958375MEB
- 294713PUC
Write an algorithm that will:
- take a potential customer identifier from the user
- if input is 鈥淨鈥, allow the user to quit the program
- if the potential customer identifier is too short, then tell the user
- if the last three characters do not follow the rules, then tell the user
- allow the user to keep entering customer identifiers
A sample output is shown.
Write an algorithm to meet the requirements.
Use pseudo-code or a programming language with which you are familiar.
[9 marks]
How to tackle the question
Pseudo-code questions are worth a large number of marks and are therefore more complex than many other questions. Make sure you read the whole question carefully. This example answer is going to use pseudo-code rather than write the answer in an actual programming language.
After reading the whole question carefully, look at the requirements. This will help you to decompose the problem.
For this question, you need to write an algorithm that will:
- take a potential customer identifier from the user
The program will need to read in the customer identifier. The identifiers contain both letters and numbers, so the program will need to read in a stringA sequence of characters often stored as a variable in a computer program. These characters can include numbers, letters and symbols. . In pseudo-code you could write:
RECEIVE identifier FROM (STRING) KEYBOARD
- if input is 鈥淨鈥, then allow user to quit the program
The program will need to check if the input contains just a 鈥淨鈥, and if it does, quit the program. This is a selection, so you can do this using an IF statementThe smallest element of a programming language which expresses an action to be carried out..
- if the potential customer identifier is too short, then tell the user
The program will need to check if the entered identifier is nine characters long (the length required is at the start of the question). If the length isn鈥檛 nine characters (again, a selection), the program needs to output an error. In pseudo-code you could write:
IF LENGTH (identifier) <> 9 THEN
聽聽聽聽聽SEND 鈥楾he customer identifier is not nine characters long鈥 TO
DISPLAY
END IF
- if the last three characters do not follow the rules, then tell the user
The start of the question tells you that the last three characters must be uppercase letters. Again, there is selection here, but it also requires you to loop iterationThe repetition of a block of statements within a computer program. through the last three characters and see if any of them are greater than or equal to 鈥楢鈥 and less than or equal to 鈥榋鈥. The question tells you how many times the algorithm has to loop so you should use a FOR loop. If the program finds a character that isn鈥檛 an uppercase letter, it will need to issue an error.
In pseudo-code you could write:
SET badAlpha TO FALSE #this is a flag that will be changed to TRUE if a non-uppercase letter is found
FOR count FROM 6 TO 8 DO
聽聽聽聽聽IF (NOT (identifier[count] >= 鈥楢鈥 AND identifier[count] <= 鈥榋鈥)) THEN
聽聽聽聽聽聽聽聽聽聽SEND 鈥楤ad character in last 3 characters found鈥 TO DISPLAY
聽聽聽聽聽聽聽聽聽聽SET badAlpha TO TRUE
聽聽聽聽聽END IF
IF badAlpha = FALSE THEN
聽聽聽聽聽SEND 鈥楩inal three characters are valid鈥 TO DISPLAY
END IF
- allow the user to keep entering customer identifiers
This tells you that you鈥檒l need a loop (iteration) of some form so that the user keeps being asked for identifiers to check until Q is entered.