#include <iostream>
class AudioBuffer {
private:
// TODO: This member is exposed and unsafe. Encapsulate it.
// TODO: Ensure it wraps around 8 (Size = 8).
int head_index;
public:
AudioBuffer() : head_index(0) {}
void advanceHead(int steps){
head_index = (head_index + steps)%8;
}
int getHeadIndex() const{
return head_index;
}
// TODO: Add a method to advance the index safely.
// TODO: Add a getter for printing.
};
int main() {
int N;
if (!(std::cin >> N)) return 0;
AudioBuffer buffer;
for (int i = 0; i < N; ++i) {
int steps;
std::cin >> steps;
// TODO: Replace unsafe direct addition
// buffer.head_index += steps; // This bugs out if index >= 8
buffer.advanceHead(steps);
// Output current state (this might be wrong if not fixed)
std::cout << "Head: " << buffer.getHeadIndex() << std::endl;
}
return 0;
}
Input
3 5 4 10
Expected Output
Head: 5 Head: 1 Head: 3