Data structures

EasyMedium
1234567891011121314151617181920212223
Question 16
Easy

A smart home network uses a record structure to represent various environmental sensors around a house.

The following pseudo-code defines the Sensor record type and instantiates three sensors:

RECORD Sensor
    location : String
    temperature : Real
    batteryLevel : Integer
    isActive : Boolean
ENDRECORD

kitchenSensor ← Sensor('Kitchen', 21.5, 85, True)
bedroomSensor ← Sensor('Bedroom', 19.2, 12, False)
garageSensor ← Sensor('Garage', 14.8, 92, True)
homeNetwork ← [kitchenSensor, bedroomSensor, garageSensor]
minBattery ← 100
lowBatteryIndex ← 0

FOR i ← 0 TO 2
    IF homeNetwork[i].batteryLevel < minBattery THEN
        minBattery ← homeNetwork[i].batteryLevel
        lowBatteryIndex ← i
    ENDIF
ENDFOR

OUTPUT 'Warning: Sensor in ', homeNetwork[lowBatteryIndex].location, ' has low battery.'

Write a single pseudo-code statement that updates the bedroomSensor record to record that the sensor has been enabled and is now active.

[1]

Data structures Questions

  1. GCSE
  2. /Computer Science
  3. /Data structures