Question: I need help debuggine my code so it will pass all the test cases. Please help! / / * * * * * * *

I need help debuggine my code so it will pass all the test cases. Please help! //**********************************
//Write your code below here
//**********************************
template
class QueueForCS2420 : public BaseQueue {
public:
// TODO: Complete constructor, copy constructor, copy assignment, and destructor, and all other needed methods
QueueForCS2420(const int capacity);
~QueueForCS2420();
QueueForCS2420(const QueueForCS2420& objToCopy);
const QueueForCS2420& operator=(const QueueForCS2420& objToCopy);
void push_back(const T& data);
void pop_front();
T front() const;
T back() const;
unsigned int size();
private:
// TODO: Supply the 5 needed data members
T* arr{ nullptr };
unsigned int capacity{0};
unsigned int slots{0};
unsigned int head{0};
unsigned int tail{0};
};
template
QueueForCS2420::QueueForCS2420(const int capacity){
// TODO: Complete this
this->arr = new T[capacity];
this->capacity = capacity;
return;
}
template
QueueForCS2420::~QueueForCS2420(){
// TODO: Complete this
delete[] this->arr;
}
template
QueueForCS2420::QueueForCS2420(const QueueForCS2420& objToCopy){
this->capacity = objToCopy.capacity;
this->slots = objToCopy.slots;
this->head = objToCopy.head;
this->tail = objToCopy.tail;
this->arr = new T[this->capacity];
for (unsigned int i =0; i this->capacity; ++i){
this->arr[i]= objToCopy.arr[i];
}
}
template
const QueueForCS2420& QueueForCS2420::operator=(const QueueForCS2420& objToCopy){
if (this != &objToCopy){
if (this->arr != nullptr){
delete[] this->arr;
}
this->capacity = objToCopy.capacity;
this->slots = objToCopy.slots;
this->head = objToCopy.head;
this->tail = objToCopy.tail;
this->arr = new T[this->capacity];
for (unsigned int i =0; i this->capacity; ++i){
this->arr[i]= objToCopy.arr[i];
}
}
return *this;
}
template
void QueueForCS2420::push_back(const T& data){
if (slots !=0)
{
if (slots == capacity){
std::cout "Error: Queue is full." std::endl;
return;
arr[tail]= data;
++tail;
}
if (tail == capacity){
tail =0;
}
++slots;
}
if (slots ==0)
{
++slots;
}
}
template
void QueueForCS2420::pop_front(){
if (slots ==0){
std::cout "Error: Queue is empty." std::endl;
return;
}
++head;
if (head == capacity){
head =0;
}
--slots;
}
template
T QueueForCS2420::front() const {
if (slots ==0){
throw std::out_of_range("Error: Queue is empty.");
}
return arr[head];
}
template
T QueueForCS2420::back() const {
if (slots ==0){
throw std::out_of_range("Error: Queue is empty.");
}
// If tail is at 0, the data is at index capacity -1
unsigned int tailIndex =(tail ==0)?(capacity -1) : (tail -1);
return arr[tailIndex];
}
template
unsigned int QueueForCS2420::size(){
/*if (slots ==0)
{
return slots =4;
}*/
return slots;
}
//**********************************
//Write your code above here
//**********************************
 I need help debuggine my code so it will pass all

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!