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:
    Packet(int id){
        this->id = id;
        this->temperature = 0;
        this->humidity = 0;
    }
    void update(int t, int h){
        this->temperature = t;
        this->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);
    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