A programmer is writing an algorithm to analyze a drone's battery log to count how many times the voltage drops between consecutive records.
RECORD BatteryLog
time : Integer
voltage : Real
capacity : Integer
ENDRECORD
log1 ← BatteryLog(10, 11.8, 85)
log2 ← BatteryLog(20, 11.5, 82)
log3 ← BatteryLog(30, 11.1, 78)
log4 ← BatteryLog(40, 10.8, 74)
log5 ← BatteryLog(50, 10.5, 70)
flightLogs ← [log1, log2, log3, log4, log5]
voltageDrops ← 0
FOR i ← 0 TO LIMIT
IF flightLogs[i + 1].voltage < flightLogs[i].voltage THEN
voltageDrops ← voltageDrops + 1
ENDIF
ENDFOR
OUTPUT 'Voltage dropped ', voltageDrops, ' times.'
What should the label LIMIT in the algorithm be replaced by to ensure the loop iterates through all adjacent pairs without causing an 'index out of bounds' error?
LEN(flightLogs)
LEN(flightLogs) - 1
LEN(flightLogs) - 2
4
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.