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.
- (a)(i)Write pseudocode to represent the algorithm.[6]
- (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]
- (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]
- (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] (a)(i) DECLARE RNum : ARRAY [1:100] OF INTEGER
- [1] (a)(i) DECLARE Index, Count : INTEGER
- [1] (a)(i) Count ← 0
- [1] (a)(i) FOR Index ← 1 TO 100
- [1] (a)(i) RNum[Index] ← INT(RAND(200)) + 1
- [1] (a)(i) IF RNum[Index] >= 66 AND RNum[Index] <= 173 THEN
- [1] (a)(i) Count ← Count + 1
- [1] (a)(i) ENDIF
- [1] (a)(i) NEXT Index
- [1] (a)(i) OUTPUT Count
- [1] (a)(ii) Initialise the array to a rogue value (to indicate 'unassigned' element)
- [1] (a)(ii) Add a conditional loop to:
- [1] (a)(ii) Generate and store a random number (in the correct range)
- [1] (a)(ii) Check the stored number against values already in the array
- [1] (a)(ii) If the stored number is found then generate another random value
- [1] (a)(ii) Otherwise add it to the array (and exit loop)
- [1] (b)(i) Give a line number containing an example of an initialisation statement.: 07
- [1] (b)(i) Give a line number containing the start of a repeating block of code.: 09 / 10
- [1] (b)(i) Give a line number containing a logic operation.: 12
- [1] (b)(i) Give the number of parameters of function MID().: 3
- [1] (b)(ii) IF (NextChar >= 'a') AND (NextChar <= 'z') THEN
- [1] (b)(ii) One mark for IF ... AND ...
- [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 →