#include <iostream>
using namespace std;

class UartConfig {
private:
    // Private members to store configuration
    int baudrate;
    int parity;
    int stopBits;

public:
    // Constructor: Initializes the private members upon object creation
    UartConfig(int b, int p, int s) {
        baudrate = b;
        parity = p;
        stopBits = s;
    }

    // Method to update all configuration fields at once
    void update(int b, int p, int s) {
        baudrate = b;
        parity = p;
        stopBits = s;
    }

    // Method to display the configuration in the required format
    void print() {
        cout << "baud=" << baudrate << " parity=" << parity << " stop=" << stopBits << endl;
    }
};

int main() {
    int b1, p1, s1;
    int b2, p2, s2;

    // Reading initial and updated configuration values
    if (!(cin >> b1 >> p1 >> s1)) return 0;
    if (!(cin >> b2 >> p2 >> s2)) return 0;

    // 1. Create the object with initial values
    UartConfig cfg(b1, p1, s1);

    // 2. Update the object with new values
    cfg.update(b2, p2, s2);

    // 3. Print the final state
    cfg.print();

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

9600 0 1 115200 1 1

Expected Output

baud=115200 parity=1 stop=1