templatetypename T> class RingBuffer { private: T* _value; int size; int front; int back; bool empty; public: RingBuffer(int s); ~RingBuffer(); void _add(T element); T get(); void _write(RingBuffer...

templatetypename T> class RingBuffer { private: T* _value; int size; int front; int back; bool empty; public: RingBuffer(int s); ~RingBuffer(); void _add(T element); T get(); void _write(RingBuffer *_value); void _read(RingBuffer *_value); bool is_empty(); int get_size(); }; Here is .cpp file: #include "RingBuffer.h" #include templatetypename T> RingBufferT>::RingBuffer(int s) :size(s) { _value = new T[size]; } templatetypename T> RingBufferT>::~RingBuffer() { if (_value!= nullptr) { delete[] _value; } } templatetypename T> void RingBufferT>::_add(T element) { if (back == front & !empty) { return; } _value[back] = element; _value[back] = (back + 1) % size; empty = false; } templatetypename T> T RingBufferT>::get() { if (back == front && empty) { return 0; } int return_value = _value[front]; front = (front + 1) % size; if (front == back) empty = true; return true; } templatetypename T> void RingBufferT>::_read(RingBuffer *_value) { while (true) { std::cout _value->get(); } } templatetypename T> void RingBufferT>::_write(RingBuffer* _value) { while (true) { std::string s; std::getline(std::cin, s); for (int i = 0; i s.size(); i++) { _value->_add(s[i]); } std::cout std::endl; } } templatetypename T> int RingBufferT>::get_size() { return size; } templatetypename T> bool RingBufferT>::is_empty() { if (back == 0) return true; else return false; } Here is main function: #include #include #include #include "RingBuffer.h" int main(){ int write = 0; int read = 0; RingBufferstd::string> _value(10); std::thread key(write, &_value); std::thread reader(read, &_value); key.join(); reader.join(); system("pause"); return 0; }
Sep 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here