Get matched

Constructing array and record programs

Start questions

AI-assisted English content review; independent teacher approval pending.

Practice scope and review

Original, AI-authored English practice with worked guidance. Selected topics only; independent teacher review is pending. This is not a complete syllabus, official past-paper collection or predicted exam score. Check your own exam-board specification: these concepts are not certified against a particular board or exam year.

151 original questions across 21 selected topic areas. No account or payment required to practise.

Cambridge International AS & A Level Computer Science (9618), examination year 2027: AI-assisted conceptual alignment to official sources, not teacher or exam-board certification. Syllabus mapping and remaining coverage.

5 questions in this topic

Exact English revisions checked in an AI-assisted academic review; independent teacher approval is still pending.

All topics

Original English exercises targeting selected 9618 2027-29 requirements. Conceptual alignment only; independent teacher approval, practical competence and complete teaching coverage are not established.

Subtopics in this topic (3)
  • Validated input
  • Two-dimensional records
  • Bubble sort and linear search

5 of 5 questions shown

Loading saved responses

Question 1Write Cambridge pseudocode to read exactly three valid integer marks into Marks[1:3]. Each must be from 0 to 10 inclusive; re-enter an invalid value without advancing the index. Output their mean as REAL. Inputs, in order, are -1, 5, 3, 11, 8. Give accepted array, sum and mean, and explain why a post-condition loop fits each input attempt.6 indicative marks

Write Cambridge pseudocode to read exactly three valid integer marks into Marks[1:3]. Each must be from 0 to 10 inclusive; re-enter an invalid value without advancing the index. Output their mean as REAL. Inputs, in order, are -1, 5, 3, 11, 8. Give accepted array, sum and mean, and explain why a post-condition loop fits each input attempt.

Show indicative guidance

Worked guidance

  1. DECLARE Marks : ARRAY[1:3] OF INTEGER
    DECLARE Index : INTEGER
    DECLARE Total : INTEGER
    DECLARE Mean : REAL
    Total <- 0
    FOR Index <- 1 TO 3
       REPEAT
          INPUT Marks[Index]
       UNTIL (Marks[Index] >= 0) AND (Marks[Index] <= 10)
       Total <- Total + Marks[Index]
    NEXT Index
    Mean <- Total / 3
    OUTPUT Mean
  2. At slot 1, -1 fails and 5 succeeds; total becomes 5. Slot 2 accepts 3, giving 8. Slot 3 rejects 11 then accepts 8, giving 16. Division / returns REAL in the guide, so the mean is 16/3, not INTEGER quotient 5.
  3. A FOR loop counts accepted slots, not every attempted input. REPEAT runs at least once per slot; placing the accumulator inside its retry body would wrongly include rejected inputs. Tests: 0 and 10 accepted, -1 and 11 rejected.

Self-marking points

View marking points
  1. Declare an INTEGER array with bounds 1:3 and an index.
  2. Use a FOR loop for three accepted slots.
  3. Repeat INPUT for the current slot until both inclusive range conditions hold.
  4. Accumulate only accepted values, giving [5,3,8].
  5. Sum is 16 and REAL division gives 16/3, approximately 5.3333.
  6. Each slot needs at least one input attempt, so REPEAT is appropriate; 0 and 10 are valid boundaries.

Examiner tip

Indicative distinct points, not an official Cambridge mark allocation. State bounds, assumptions and intermediate states; practical teacher review remains required.

Question 2A room has two rows and three seats per row. Define a Seat record with Occupied: BOOLEAN and Name: STRING, then Seats[1:2,1:3] OF Seat. Write CountOccupied() returning the number occupied without changing records. Occupied values are row1 [TRUE,FALSE,TRUE], row2 [FALSE,TRUE,FALSE]. Trace the returned count and explain why one array of STRING names alone is a weaker model.6 indicative marks

A room has two rows and three seats per row. Define a Seat record with Occupied: BOOLEAN and Name: STRING, then Seats[1:2,1:3] OF Seat. Write CountOccupied() returning the number occupied without changing records. Occupied values are row1 [TRUE,FALSE,TRUE], row2 [FALSE,TRUE,FALSE]. Trace the returned count and explain why one array of STRING names alone is a weaker model.

Show indicative guidance

Worked guidance

  1. TYPE Seat
       DECLARE Occupied : BOOLEAN
       DECLARE Name : STRING
    ENDTYPE
    DECLARE Seats : ARRAY[1:2,1:3] OF Seat
    FUNCTION CountOccupied() RETURNS INTEGER
       DECLARE Row : INTEGER
       DECLARE Column : INTEGER
       DECLARE Count : INTEGER
       Count <- 0
       FOR Row <- 1 TO 2
          FOR Column <- 1 TO 3
             IF Seats[Row,Column].Occupied THEN
                Count <- Count + 1
             ENDIF
          NEXT Column
       NEXT Row
       RETURN Count
    ENDFUNCTION
  2. The six tests produce running counts 1,1,2,2,3,3, so the returned value is 3. Each record groups heterogeneous fields describing one seat; the array itself remains homogeneous because every element is a Seat.
  3. The function returns a value for use in an expression, such as OUTPUT CountOccupied(); it is not called with CALL. An empty name need not reliably mean an unoccupied seat, so a typed Boolean records the state independently.

Self-marking points

View marking points
  1. Define Seat with both correctly typed fields.
  2. Declare the 2D array with explicit inclusive bounds.
  3. Initialise the count to zero.
  4. Visit every row/column and increment only for Occupied=TRUE.
  5. Return INTEGER 3, with row totals 2 and 1.
  6. A separate occupancy field avoids overloading a possibly empty name to represent seat state.

Examiner tip

Indicative distinct points, not an official Cambridge mark allocation. State bounds, assumptions and intermediate states; practical teacher review remains required.

Question 4Write pseudocode returning the maximum of nonempty integer A[1:N], with N>=1, without sorting. Trace A=[-8,-3,-9,-3], giving the stored maximum after each element. Explain the failure of starting Largest at 0 and test N=1 with A=[-5].4 indicative marks

Write pseudocode returning the maximum of nonempty integer A[1:N], with N>=1, without sorting. Trace A=[-8,-3,-9,-3], giving the stored maximum after each element. Explain the failure of starting Largest at 0 and test N=1 with A=[-5].

Cambridge 2027: Direct conceptual match

Checked negative and tied data, one-element path and invalid zero sentinel; this is a linear construction, not another sorting trace.

AI-assisted placement. Independent teacher approval pending.

Show indicative guidance

Worked guidance

  1. Largest <- A[1]
    FOR I <- 2 TO N
       IF A[I] > Largest THEN
          Largest <- A[I]
       ENDIF
    NEXT I
    OUTPUT Largest
  2. Starting with -8 makes Largest an actual member. The next value raises it to -3, and neither -9 nor the tied -3 raises it further.
  3. With one element the FOR body has no iterations and returns -5. Starting at 0 would falsely dominate every negative value, violating the requirement to return a member maximum.

Self-marking points

View marking points
  1. Initialises Largest from A[1].
  2. Scans indices 2..N, updating only for a larger element.
  3. Trace is -8,-3,-3,-3 and final maximum -3.
  4. Zero initialisation wrongly returns 0; single-element test returns -5.

Examiner tip

State the nonempty-array precondition before accessing A[1].

Question 5Integer Codes[1:5]=[2,1,2,3,2] contains only category codes 1..3. Construct pseudocode filling Count[1:3] with each category frequency. Show Count after the first three inputs and after all five; state a useful total-count check.4 indicative marks

Integer Codes[1:5]=[2,1,2,3,2] contains only category codes 1..3. Construct pseudocode filling Count[1:3] with each category frequency. Show Count after the first three inputs and after all five; state a useful total-count check.

Cambridge 2027: Direct conceptual match

Independently tallied frequencies1/3/1, intermediate1/2/0 and conservation total5; explicit valid-index precondition.

AI-assisted placement. Independent teacher approval pending.

Show indicative guidance

Worked guidance

  1. FOR K <- 1 TO 3
       Count[K] <- 0
    NEXT K
    FOR I <- 1 TO 5
       Count[Codes[I]] <- Count[Codes[I]] + 1
    NEXT I
  2. The first three codes 2,1,2 yield counters [1,2,0]; the index is the category value, not the input position.
  3. Code 3 then adds the third category and the final 2 raises its count: [1,3,1]. Their sum 5 accounts for every supplied valid code exactly once.

Self-marking points

View marking points
  1. Initialises all three counters to zero.
  2. Increments Count[Codes[I]] once per element.
  3. After three: [1,2,0]; final: [1,3,1].
  4. Checks sum of final counters equals 5.

Examiner tip

Array-index validation would be required if category values were not guaranteed.

All AS & A Level subjects