ADCChannel Constructor Validation

#include <iostream>
using namespace std;

// Write your ADCChannel class here
class ADCChannel {
private:
    int channel;
    int resolution;
public:
    ADCChannel(int ch, int res) {
        if(ch < 0) channel = 0;
        else if(ch > 15) channel = 15;
        else channel = ch;

        if(res != 8 && res != 10 && res != 12) resolution = 12;
        else resolution = res;
    }
    void print() {
        cout << "CH=" << channel << " RES=" << resolution;
    }
};

int main() {
    int ch, res;
    cin >> ch >> res;

    ADCChannel adc(ch, res);
    adc.print();

    return 0;
}
Upvote
Downvote
Loading...

Input

3 10

Expected Output

CH=3 RES=10