74. BufferTracker Destructor Logging

Create a class BufferTracker that simulates processing bytes in a communication buffer (UART, SPI, DMA, etc.).

Each time addByte() is called, an internal counter increases.
When the object is destroyed, the destructor must automatically print:

PROCESSED=<count>

This simulates firmware that logs how many bytes were processed during a communication transaction.

Class Requirements:

  • A private integer count, initialized to 0
  • Constructor initializes count = 0
  • void addByte(int b) increases count by 1
  • Destructor prints
    • PROCESSED=<count>
  • No static variables allowed

Program Behavior:

  1. Read integer n — number of bytes
  2. Create a BufferTracker object inside a scoped block { }
  3. Read n byte values (values are irrelevant)
  4. For each byte, call addByte()
  5. When the block ends, the destructor automatically prints the processed count

⚠️ Nothing should be printed inside the block — only the destructor prints output

 

Example 1

Input:

5
10 20 30 40 50

Output:

PROCESSED=5 

 

Example 2

Input:

0

Output:

PROCESSED=0 

 

Constraints:

  • Destructor must be the only place where output occurs
  • Count must exactly match the number of addByte() calls
  • Output must match exactly

 

 

 

 

Loading...

Input

5 1 2 3 4 5

Expected Output

PROCESSED=5