ADCChannel Constructor Validation

#include <iostream>
using namespace std;

// Write your ADCChannel class here
class ADCChannel{
    int channel;
    int resolution;
    public:
    ADCChannel(int ch, int res){
        channel=ch<0 ? 0 : ch>15 ? 15 : ch;
        resolution=res==8 || res==10 || res==12 ? res : 12;
    }
    void print(){
        printf("CH=%d RES=%d",channel,resolution);
    }
};
int main() {
    int ch, res;
    cin >> ch >> res;

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

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

3 10

Expected Output

CH=3 RES=10