78. UART Frame Builder

Create a class named Frame that represents a UART transmit frame with a maximum capacity of 16 bytes.

The class must internally store bytes using a fixed-size array and must not use dynamic memory allocation.

You are required to overload operators to make frame construction intuitive and safe for firmware-style usage.

Requirements

You must implement the following in the Frame class:

  • A fixed internal buffer of 16 bytes
  • A variable to track the current frame size
  • operator+= to append a single byte to the frame
  • operator[] to access a byte by index for read-only purposes
  • A method to retrieve the current frame size

The frame must never exceed 16 bytes. The input provided will always respect this limit.

Program Behavior

Your program must:

  1. Read an integer n — the number of bytes to append
  2. Read n integers, each representing a byte value in the range 0–255
  3. Append each byte to the frame using the overloaded operator+=
  4. Print the final frame contents in order, separated by single spaces

 

Input Format

n
b1 b2 b3 ... bn
  • n is an integer where 1 ≤ n ≤ 16
  • Each b is an integer where 0 ≤ b ≤ 255

Output Format

b1 b2 b3 ... bn

Each value must be printed as a decimal integer, separated by a single space.

 

Example 1

Input:

4
10 20 30 40

Output:

10 20 30 40

 

Example 2

Input:

3
255 0 128

Output:

255 0 128

 

Constraints

  • Internal storage type must be uint8_t
  • Maximum frame size is 16 bytes
  • No dynamic memory allocation (new, malloc, STL containers, etc.)
  • Only operator+= and operator[] may be used for frame access
  • Output formatting must match exactly

 

 

Loading...

Input

4 10 20 30 40

Expected Output

10 20 30 40