Skip to content

Course home

Algorithms

Algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
Question 45

A student is writing an algorithm for a smart locker system. Compartments are tracked using arrays.

1  SET lockerGroupA TO ["", "", "", "", "", ""]
2  SET occupiedA TO 0
3  SET lockerGroupB TO ["", "", "", "", "", ""]
4  SET occupiedB TO 0
5  SET operationalStatus TO "Ready"
6  SET systemLocked TO False
7
8  DEFINE FUNCTION assignLocker(pGroup, pPasscode)
9      DECLARE assigned AS BOOLEAN
10     SET assigned TO False
11     IF pGroup == "Alpha" THEN
12         IF occupiedA < 6 THEN
13             SET lockerGroupA[occupiedA] TO pPasscode
14             SET occupiedA TO occupiedA + 1
15             SET assigned TO True
16         END IF
17     ELSE
18         IF pGroup == "Beta" THEN
19             IF occupiedB < 6 THEN
20                 SET lockerGroupB[occupiedB] TO pPasscode
21                 SET occupiedB TO occupiedB + 1
22                 SET assigned TO True
23             END IF
24         END IF
25     END IF
26     OUTPUT "Success: " & assigned
27     RETURN assigned
28 END FUNCTION

State a line number of an instruction in the algorithm that assigns a value to an element of an array.

[1]
Markscheme

Algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Algorithms

159 exam-style questions on Edexcel GCSE Computer Science Algorithms, covering Constructs for solving problems, Variables, constants and data structures, Arithmetic, relational and logical operators, Tracing algorithm output with trace tables, Types of error and correcting logic errors, Standard algorithms (sorts and searches), and Evaluating algorithm fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank