Sensor Packet Handling

#include <iostream>
using namespace std;
 
// Define Packet class here
class Packet{
    int id;
    int temperature;
    int humidity;

    public:
    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<<endl;
    }
};
// <write your code>
 
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