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
template
template
template
{ DataType temp; return temp; }
template
// Removes all the data items from a queue. { }
template
template
template
// Enqueues newDataItem at the front of the queue -- // deque behavior -- instead of at the back as would normally happen. { }
template
// 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
//--------------------------------------------------------------------
template
{ 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
using namespace std;
#include "Queue.h"
template
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
using namespace std;
#pragma warning( disable : 4290 )
//--------------------------------------------------------------------
template
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
#endif // #ifndef QUEUE_H
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
