14. Sensor with Thresholds Class

 Frame a class Sensor with the following:

  • Private data members:
    • id (integer, sensor ID)
    • value (integer, current reading)
       
  • Public methods:
    • Constructor Sensor(int id, int value)
    • void setValue(int v) → updates the reading
    • bool isAboveThreshold(int t) const → returns true if value >= t
    • int getId() const → returns the sensor ID
       

The input will contain:

  • n (number of sensors)
  • followed by n lines, each: id value threshold
     For each sensor, print either:
Sensor <id>: ALERT

or

Sensor <id>: NORMAL

depending on whether the reading meets/exceeds the threshold.

 

Example
 Input:

3
101 75 60
202 30 50
303 100 100

 Output:

Sensor 101: ALERT
Sensor 202: NORMAL
Sensor 303: ALERT

Here, n = 3. For the first line: id = 101, value = 75, threshold = 60.
Explanation:

  • For 101: 75 ≥ 60 → ALERT
  • For 202: 30 < 50 → NORMAL
  • For 303: 100 ≥ 100 → ALERT
     

Input:

2
1 0 1
2 255 128

Output:

Sensor 1: NORMAL
Sensor 2: ALERT

Explanation:

  • 1: 0 < 1 → NORMAL
  • 2: 255 ≥ 128 → ALERT
     
Loading...

Input

3 101 75 60 202 30 50 303 100 100

Expected Output

Sensor 101: ALERT Sensor 202: NORMAL Sensor 303: ALERT