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:
Buffer class that stores one integerDriver class that owns a BufferProgram Flow:
Driver inside a local scopeDriver stores the value in its internal bufferDriver prints the stored valueDriver shuts downBuffer is destroyed automaticallyInput:
One signed integerOutput (exact order, each on its own line):
Buffer created
Driver initialized
Stored value: <value>
Driver destroyed
Buffer destroyedConstraints:
Buffer must not be created in main()Buffer access only through Driverint range
Input
10
Expected Output
Buffer created Driver initialized Stored value: 10 Driver destroyed Buffer destroyed