Write an O-O program to simulate a keyboard buffer using an array.
Define "#define MAXBUFFER 16" at the top of your program to set the maximum number of keystrokes that may be stored in the buffer.
The keyboard buffer ADT must contain functions to "Enter" a keystroke and "Retrieve" a keystroke. "Enter" will take a single character as a parameter and add the keystroke to the data structure. "Retrieve" will return a single character from the data structure.
The keyboard buffer must be implemented as an object which stores single-character keystrokes in an array, with appropriate position indicators for the beginning and end of the array. Be careful to handle wrapping around of the array when any pointers go beyond the range of the array.
Your keyboard buffer class definition should have the general form :
class KeyboardBuffer
{
void Enter ( unsigned char aKey );
unsigned char Retrieve ();
...
Include a method called "Error", whose non-zero value will indicate what error had occurred (0=no error, 1=overflow, 2=underflow) in the last transaction.
Test the program by adding and removing keystrokes from the buffer. Test also to see if the program correctly handles overflow (buffer is full and Enter is called) and underflow (buffer is empty and Retrieve is called).