GPIO Pin Class

#include <iostream>
using namespace std;

// Define class GpioPin here
// <write your code>
\
class GpioPin {
public:
    int pinNumber;
    GpioPin () : pinNumber(0){};
    void write(int val);
    int read();
private:
    int pin_state;
};

void GpioPin::write(int val){
    this->pin_state = val;
}

int GpioPin::read(){
    return this->pin_state;
}

int main() {
    int pin, initialValue, finalValue;
    cin >> pin >> initialValue >> finalValue;

    GpioPin gpio;          // default constructor
    gpio.pinNumber = pin; // manual assignment

    gpio.write(initialValue);
    gpio.write(finalValue);

    cout << "GPIO Pin " << gpio.pinNumber
         << " State " << gpio.read();

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

13 0 1

Expected Output

GPIO Pin 13 State 1