UART Initialization Defaults

#include <iostream>
using namespace std;
 
void initUART(int baurd_rate,char parity='N',int stop_bits=1){
    cout<<baurd_rate<<" " <<parity<<" "<<stop_bits<<endl;
}
 
int main() {
    int baud, mode;
    cin >> baud >> mode;
 
    if (mode == 0) {
        
        initUART(baud);
    } else if (mode == 1) {
        char parity;
        cin >> parity;
        initUART(baud, parity);
    } else if (mode == 2) {
        char parity;
        int stopBits;
        cin >> parity >> stopBits;
        initUART(baud, parity, stopBits);
    }
 
    return 0;
}

Solving Approach

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

9600 0

Expected Output

9600 N 1