Skip to main content
A-LevelComputer ScienceProgramming9618/22 · May/June 2021 · Q515 Marks

A student is learning about arrays. She wants to write a program to: • declare a 1D array RNum of 100 elements of type INTEGER • assign each element a random value in the range 1 to 200 inclusive • count and output how many numbers generated were between 66 and 173 inclusive.

  1. (a)(i)Write pseudocode to represent the algorithm.[6]
  2. (a)(ii)The student decides to modify the algorithm so that each element of the array will contain a unique value. Describe the changes that the student needs to make to the algorithm.[3]
  3. (b)(i)The following is a pseudocode function. Line numbers are given for reference only. 01 FUNCTION StringClean(InString : STRING) RETURNS STRING 02 03 DECLARE NextChar : CHAR 04 DECLARE OutString : STRING 05 DECLARE Counter : INTEGER 06 07 OutString ← "" 08 09 FOR Counter ← 1 TO LENGTH(InString) 10 NextChar ← MID(InString, Counter, 1) 11 NextChar ← LCASE(NextChar) 12 IF NOT((NextChar < 'a') OR (NextChar > 'z')) THEN 13 OutString ← OutString & NextChar 14 ENDIF 15 NEXT Counter 16 17 RETURN OutString 18 19 ENDFUNCTION Examine the pseudocode and complete the following table. Give a line number containing an example of an initialisation statement. Give a line number containing the start of a repeating block of code. Give a line number containing a logic operation. Give the number of parameters to the function MID().[4]
  4. (b)(ii)Write a simplified version of the statement in line 12.[2]

Mark scheme

Marking points from the official mark scheme (May/June 2021). The mark or mark type is shown in brackets.

  1. [1] (a)(i) DECLARE RNum : ARRAY [1:100] OF INTEGER
  2. [1] (a)(i) DECLARE Index, Count : INTEGER
  3. [1] (a)(i) Count ← 0
  4. [1] (a)(i) FOR Index ← 1 TO 100
  5. [1] (a)(i) RNum[Index] ← INT(RAND(200)) + 1
  6. [1] (a)(i) IF RNum[Index] >= 66 AND RNum[Index] <= 173 THEN
  7. [1] (a)(i) Count ← Count + 1
  8. [1] (a)(i) ENDIF
  9. [1] (a)(i) NEXT Index
  10. [1] (a)(i) OUTPUT Count
  11. [1] (a)(ii) Initialise the array to a rogue value (to indicate 'unassigned' element)
  12. [1] (a)(ii) Add a conditional loop to:
  13. [1] (a)(ii) Generate and store a random number (in the correct range)
  14. [1] (a)(ii) Check the stored number against values already in the array
  15. [1] (a)(ii) If the stored number is found then generate another random value
  16. [1] (a)(ii) Otherwise add it to the array (and exit loop)
  17. [1] (b)(i) Give a line number containing an example of an initialisation statement.: 07
  18. [1] (b)(i) Give a line number containing the start of a repeating block of code.: 09 / 10
  19. [1] (b)(i) Give a line number containing a logic operation.: 12
  20. [1] (b)(i) Give the number of parameters of function MID().: 3
  21. [1] (b)(ii) IF (NextChar >= 'a') AND (NextChar <= 'z') THEN
  22. [1] (b)(ii) One mark for IF ... AND ...
  23. [1] (b)(ii) One mark for both conditions

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 15 marks.
Source
A-Level Computer Science, May/June 2021 Paper 2 Variant 2, question 5.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep