#include <iostream>
using namespace std;

// Write your PWMController class here
class PWMController{
    int frequency;
    int duty;
    bool enabled;

    public:

    PWMController(int frequency): frequency(frequency),duty(0),enabled(false) {}
    PWMController(int frequency, int d): frequency(frequency),enabled(true) {
        d= d>100? 100:d;
        d= d<0? 0:d;
        duty = d;
    }

    void setDuty(int d){
        duty = d;
    }
    void disable(){
        enabled = false;
    }
    void print(){
        cout<<"F="<<frequency<<" D="<<duty<<" EN="<<enabled;
    }
};

int main() {
    int mode;
    cin >> mode;

    PWMController pwm(0); // temporary placeholder

    if (mode == 1) {
        int f;
        cin >> f;
        pwm = PWMController(f);
    }
    else {
        int f, d;
        cin >> f >> d;
        pwm = PWMController(f, d);
    }

    int x;
    cin >> x;

    if (x == -1)
        pwm.disable();
    else
        pwm.setDuty(x);

    pwm.print();
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

1 1000 50

Expected Output

F=1000 D=50 EN=0