For this assignment I need to implement a c++ class that creates a ring buffer. A ring buffer still uses an array, but its has two indices, i..e., the head and the tail. Note: The head is the index of the first data point, and the tail by definition is the index of the last data point plus 1 (i.e., the tail indicates the first one that is not of interest). Therefore, if you use an array of N elements for this ring buffer, this ring buffer can actually hold N-1 data point. This is very important, because head==tail is the condition for an empty buffer.
This is the class that I need to implement, followed by the void main() function I need to test it with:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#define SIZE 10 // don’t modify this number
class CRingBuffer
{
int m_buffer[SIZE];
int m_head; // the position of the first element
int m_tail; // the position after the last element
public:
CRingBuffer(); // constructor
~CRingBuffer() { }; // destructor
bool isfull(); // check if the buffer is full
bool isempty(); // check if the buffer is empty
void put(int data); // always put the data at end
bool get(int &data); // always get the data of the current head
int size(); // return the actual size of elements in the buffer
void dump(); // dump all the debug information
};
void main()
{
CRingBuffer buff;
buff.dump();
for(int k=1;k<=20;k++)
{
buff.put(k);
2
buff.dump();
}
cout << "\n\n";
int d;
for(k=0; k<10; k++)
{
buff.get(d);
buff.dump();
}
cout << “Press any key to exit.”;
getchar();
}
What I need help with is definining each function underneith "public" in the class CRingBuffer definition. I'm fairly confused as to how to implement these, so any help that anyone could give me would be great. Thanks!!