Photo AI
Question 9
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
Step 1
Answer
Initialize the counts array
SET counts TO [[2, 0], [8, 0], [5, 0], [4, 0], [1, 0], [3, 0], [6, 0], [7, 0]]
Declare the variable inBarrier
INTEGER inBarrier
Increment Function Create a function to increment the count for the barrier that sent the signal:
FUNCTION incrementBarrierCount(inBarrier)
BOOLEAN found = false
INTEGER index
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
Increment the count If the barrier is found, increment the count:
IF found THEN
counts[index][1] = counts[index][1] + 1
END IF
End Function End the incrementBarrierCount function to complete the program.
Report Improved Results
Recommend to friends
Students Supported
Questions answered