#include <iostream>
using namespace std;
class Packet {
private:
int id;
int temperature;
int humidity;
public:
// Constructor initializes ID and resets sensor values
Packet(int i) : id(i), temperature(0), humidity(0) {}
void update(int t, int h) {
temperature = t;
humidity = h;
}
void print() {
cout << "ID=" << id
<< " TEMP=" << temperature
<< " HUM=" << humidity;
}
};
int main() {
int id, t1, h1, t2, h2;
cin >> id >> t1 >> h1 >> t2 >> h2;
Packet pkt(id);
pkt.update(t1, h1); // first sample
pkt.update(t2, h2); // second sample
pkt.print();
return 0;
}
Explanation & Logic Summary:
Packet represents a small embedded data structure holding telemetry valuesupdate() simulates receiving new sensor measurementsprint() outputs the packet contents in a deterministic formatFirmware Relevance & Real-World Context:
Input
7 20 40 25 45
Expected Output
ID=7 TEMP=25 HUM=45