96. Driver Owns Buffer

In embedded systems, a driver often owns internal buffers that must exist only while the driver exists.
When the driver shuts down, all owned resources must be released in a deterministic order.

Your task is to model this using composition and observe the construction and destruction order.

Do This:

  • Create a Buffer class that stores one integer
  • Create a Driver class that owns a Buffer
  • Read one integer from input
  • Store it in the buffer via the driver
  • Print the stored value
  • Observe destruction when the driver goes out of scope

Program Flow:

  1. Read one integer
  2. Create a Driver inside a local scope
  3. Driver stores the value in its internal buffer
  4. Driver prints the stored value
  5. Scope ends
  6. Driver shuts down
  7. Buffer is destroyed automatically

Input:

One signed integer

Output (exact order, each on its own line):

Buffer created
Driver initialized
Stored value: <value>
Driver destroyed
Buffer destroyed

Constraints:

  • Buffer must not be created in main()
  • Buffer access only through Driver
  • No dynamic allocation
  • No inheritance
  • Must support full signed int range
  • Output format must match exactly

 

 

Loading...

Input

10

Expected Output

Buffer created Driver initialized Stored value: 10 Driver destroyed Buffer destroyed