15. Sensor Filter Selection

A sensor reading may optionally be passed through a filtering step.

You must create a function that:

  • Always receives a raw sensor value as the first parameter.
  • Optionally receives a filter mode as the second parameter.
  • Uses no filtering by default if the filter mode is not provided.
     

Filtering Behavior

Implement filtering as follows:

  • NONE (default) → return the raw value unchanged
  • LOW → return raw / 2 (basic smoothing)
  • HIGH → return raw / 4 (strong smoothing)

All divisions use integer division.

Filter modes must be represented using an enum, not integers.

Program Behavior (main)

  1. Read an integer raw and an integer modeFlag.
  2. If modeFlag == 0:
    • Call the function using the default filter mode.
  3. If modeFlag == 1:
    • Read a string filter name ("LOW" or "HIGH").
    • Call the function using the specified filter mode.
  4. Print the filtered sensor reading.

Assume all inputs are valid.

 

Example 1

Input:

100 0

Output:

100

 

Example 2

Input:

100 1 LOW

Output:

50

 

Example 3

Input:

100 1 HIGH

Output:

25

 

Constraints

  • Use an enum type to represent filter modes.
  • Use a default argument so the function can be called with or without specifying the filter mode.
  • Integer arithmetic is sufficient for this task.
     

 

 

Loading...

Input

100 0

Expected Output

100