Sensor Packet Handling

#include <iostream>
using namespace std;
 
// Define Packet class here
// <write your code>
 
class Packet {
    private:
    int id;
    int temperature;
    int humidity;

    public:
    explicit Packet (int id) noexcept : id(id), temperature(0), humidity(0) {};
    void update (int i, int h) noexcept
    {
        temperature = i;
        humidity = h;
    }

    void print () const noexcept 
    {
        cout << "ID=" << id << " TEMP=" << temperature << " HUM=" << humidity << endl;
    }
};
int main() {
    int id, t1, h1, t2, h2;
    cin >> id >> t1 >> h1 >> t2 >> h2;
 
    Packet pkt(id);
    pkt.update(t1, h1);
    pkt.update(t2, h2);
 
    pkt.print();
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

7 20 40 25 45

Expected Output

ID=7 TEMP=25 HUM=45