64. Sensor Packet Handling

You must define a class Packet that represents a small telemetry packet sent from a sensor module.

Your class must:

  1. Store the following private members:
    • int id
    • int temperature
    • int humidity
  2. Provide:
    • A constructor that sets id and initializes temperature and humidity to 0
    • A method void update(int t, int h)
      • Updates temperature and humidity
    • A method void print()
      • Prints the packet contents in the format:
        • ID=<id> TEMP=<temperature> HUM=<humidity>
  3. In main():
    • Read id, t1, h1, t2, h2
    • Create a Packet object with the given id
    • Call update(t1, h1)
    • Call update(t2, h2)
    • Print the final packet using print()

Example Input:

7 20 40 25 45

Example Output:

ID=7 TEMP=25 HUM=45 

Constraints:

  • All data members (id, temperature, humidity) must be private
  • Constructor must initialize temperature and humidity to 0
  • Print format must match exactly

 

 

 

Loading...

Input

7 20 40 25 45

Expected Output

ID=7 TEMP=25 HUM=45