A AudioBuffer class acts as a circular buffer (ring buffer) for processing audio samples. It has a fixed capacity of 8 slots. The class tracks the buffer's state using a head_index, which indicates where the next sample will be written. Currently, head_index is public. Client code frequently adds samples by directly adding to the index (e.g., index += samples), forgetting to handle the wrap-around logic. This causes the index to exceed the buffer size, leading to out-of-bounds memory access. Your task is to encapsulate the head_index. Implement a public method advanceHead(int steps) that:
steps.Program Flow:
AudioBuffer (index starts at 0).N (number of operations).N times:steps (number of samples processed).head_index.Input Format:
N (number of inputs).N lines: Integer steps (amount to advance).Output Format:
Head: <value>Example:
Example 1
Input:
3
5
4
10Output:
Head: 5
Head: 1
Head: 3
Constraints:
N range: 1 to 20steps range: 0 to 1000
Input
3 5 4 10
Expected Output
Head: 5 Head: 1 Head: 3