Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
Question 73

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?

A

LEN(flightLogs)

B

LEN(flightLogs) - 1

C

LEN(flightLogs) - 2

D

4

Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

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.

Question bank