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

Algorithm to Increment the Count for Each Barrier

96%

114 rated

Answer

  1. Initialize Count: Begin by setting the count for each barrier in the array counts. Each inner array corresponds to a barrier and has two elements: the barrier number and the count.

  2. Retrieve inBarrier: Determine which barrier has been signaled and stored in the variable inBarrier.

  3. Increment Count:

    • Use a for loop to iterate through the counts array.

    • Check if the current index matches inBarrier.

    • If a match is found, increment the count for that barrier. This can be done using:

      counts[i][1] = counts[i][1] + 1;
      
  4. Complete Loop: Exit the loop once the count for the relevant barrier has been incremented. There is no need to continue checking other barriers once a match is found.

  5. End of Algorithm: End the process once the count has been successfully updated.

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

;