Photo AI

Passengers are counted as they go through the security barriers - Edexcel - GCSE Computer Science - Question 9 - 2020 - Paper 1

Question icon

Question 9

Passengers-are-counted-as-they-go-through-the-security-barriers-Edexcel-GCSE Computer Science-Question 9-2020-Paper 1.png

Passengers are counted as they go through the security barriers. There are currently eight barriers operating. The number of barriers may change. A barrier sends a... show full transcript

Worked Solution & Example Answer:Passengers are counted as they go through the security barriers - Edexcel - GCSE Computer Science - Question 9 - 2020 - Paper 1

Step 1

Write an algorithm to increment the count for each barrier in the two-dimensional array.

96%

114 rated

Answer

  1. Initialize the counts array

    SET counts TO [[2, 0], [8, 0], [5, 0], [4, 0], [1, 0], [3, 0], [6, 0], [7, 0]]
    
  2. Declare the variable inBarrier

    INTEGER inBarrier
    
  3. Increment Function Create a function to increment the count for the barrier that sent the signal:

    FUNCTION incrementBarrierCount(inBarrier)
        BOOLEAN found = false
        INTEGER index
    
  4. Loop through the counts array Use a while loop to find the correct index:

    index = 0
    WHILE index < LENGTH(counts) AND NOT found DO
        IF counts[index][0] = inBarrier THEN
            found = true
        ELSE
            index = index + 1
        END IF
    END WHILE
    
  5. Increment the count If the barrier is found, increment the count:

    IF found THEN
        counts[index][1] = counts[index][1] + 1
    END IF
    
  6. End Function End the incrementBarrierCount function to complete the program.

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;