Question: Could you please help. This needs to be in C++. The cpp file needs to be implemented. I will include the header and cpp file

Could you please help. This needs to be in C++. The cpp file needs to be implemented. I will include the header and cpp file that needs the implementation on it.

QueueArray.cpp

#include "QueueArray.h"

template QueueArray::QueueArray(int maxNumber) // Creates an empty queue. Allocates enough memory for maxNumber // data items (defaults to MAX_QUEUE_SIZE in class declaration). { }

template QueueArray::~QueueArray() // Frees the memory used by a queue. { }

template void QueueArray::enqueue(const DataType& newDataItem) throw (logic_error) // Inserts newDataItem at the rear of a queue. { }

template DataType QueueArray::dequeue() throw (logic_error) // Removes the least recently added (front) data item from a queue // and returns it.

{ DataType temp; return temp; }

template void QueueArray::clear()

// Removes all the data items from a queue. { }

template bool QueueArray::isEmpty() const { return false; }

template bool QueueArray::isFull() const { return false; }

template void QueueArray::putFront(const DataType& newDataItem) throw (logic_error)

// Enqueues newDataItem at the front of the queue -- // deque behavior -- instead of at the back as would normally happen. { }

template DataType QueueArray::getRear() throw (logic_error)

// Removes and returns the dataItem at the rear of the queue -- // deque behavior -- instead of at the head as would normally happen. { DataType temp; return temp; }

template int QueueArray::getLength() const // Calculates and returns the length of the queue. { return -1; }

//--------------------------------------------------------------------

template void QueueArray::showStructure() const // Array implementation. Outputs the data items in a queue. If the // queue is empty, outputs "Empty queue". This operation is intended // for testing and debugging purposes only.

{ int j; // Loop counter

if ( front == -1 ) cout << "Empty queue" << endl; else { cout << "Front = " << front << " Back = " << back << endl; for ( j = 0 ; j < maxSize ; j++ ) cout << j << "\t"; cout << endl; if ( back >= front ) for ( j = 0 ; j < maxSize ; j++ ) if ( ( j >= front ) && ( j <= back ) ) cout << dataItems[j] << "\t"; else cout << " \t"; else for ( j = 0 ; j < maxSize ; j++ ) if ( ( j >= front ) || ( j <= back ) ) cout << dataItems[j] << "\t"; else cout << " \t"; cout << endl; } }

QueueArray.h

// QueueArray.h

#ifndef QUEUEARRAY_H #define QUEUEARRAY_H

#include #include

using namespace std;

#include "Queue.h"

template class QueueArray : public Queue { public: QueueArray(int maxNumber = Queue::MAX_QUEUE_SIZE); QueueArray(const QueueArray& other); QueueArray& operator=(const QueueArray& other); ~QueueArray();

void enqueue(const DataType& newDataItem) throw (logic_error); DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const; bool isFull() const;

void putFront(const DataType& newDataItem) throw (logic_error); DataType getRear() throw (logic_error); int getLength() const;

void showStructure() const;

private: int maxSize; int front; int back; DataType* dataItems; };

#endif

Queue.h

//-------------------------------------------------------------------- // // Laboratory 7 Queue.h // // Class declaration of the abstract class interface to be used as // the basis for implementations of the Queue ADT. // //--------------------------------------------------------------------

#ifndef QUEUE_H #define QUEUE_H

#include #include

using namespace std;

#pragma warning( disable : 4290 )

//--------------------------------------------------------------------

template class Queue { public: static const int MAX_QUEUE_SIZE = 8;

virtual ~Queue();

virtual void enqueue(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType dequeue() throw (logic_error) = 0;

virtual void clear() = 0;

virtual bool isEmpty() const = 0; virtual bool isFull() const = 0;

// The conditional compilation tests below are very important. // Because the functions declared are pure virtual functions, if they // are declared in the base class, then they MUST be implemented in any // derived classes. But they are supposed to be optional implementations. // Consequently, they must only be declared here if they are being // implemented in the derived classes. #if LAB7_TEST2 virtual void putFront(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType getRear() throw (logic_error) = 0; #endif #if LAB7_TEST3 virtual int getLength() const = 0; #endif

virtual void showStructure() const = 0; };

template Queue::~Queue() // Not worth having a separate class implementation file for the destuctor {}

#endif // #ifndef QUEUE_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!