61. UART Config Class

Define a class UartConfig that represents configuration parameters of a UART peripheral in an embedded system.

Your class must:

  1. Store the following private members:
    • int baudrate
    • int parity
      • 0 = none
      • 1 = even
      • 2 = odd
    • int stopBits
      • valid values: 1 or 2
  2. Provide the following public members:
    • A constructor that initializes all three configuration fields.
    • A method void update(int b, int p, int s) which updates all configuration fields.
    • A method void print() which prints the configuration exactly in the format:
      • baud=<value> parity=<value> stop=<value>
        
  3. In main():
    • Read three integers b1 p1 s1 representing the initial UART configuration.
    • Read three integers b2 p2 s2 representing the updated UART configuration.
    • Create a UartConfig object using the initial values.
    • Update the object using the second set of values.
    • Print the final configuration using print().

Example Input:

9600 0 1 115200 1 1 

Example Output:

baud=115200 parity=1 stop=1 

Constraints:

  • All member variables must be private.
  • The constructor must be used to initialize the object.
  • The update() method must be used to modify the configuration.
  • print() must produce exactly the required output format.
  • No validation logic is required; inputs are guaranteed to be valid.
  • Use standard input/output (cin / cout) only.

 

 

 

 

 

Loading...

Input

9600 0 1 115200 1 1

Expected Output

baud=115200 parity=1 stop=1