Also if you could break it down for me like bold queueADTh a

Also if you could break it down for me like bold queueADT.h and   queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file thank you so much for your help

Write the definition of the function moveNthFront that takes as a para- meter a positive integer, n. The function moves the nth element of the queue to the front. The order of the remaining elements remains unchanged.

For example, suppose:
queue = {5, 11, 34, 67, 43, 55} and n = 3

After a call to the function moveNthFront:
queue = {34, 5, 11, 67, 43, 55}

Add this function to the class queueType.

Also, write a program to test your method.

Use the file names listed below since your file will have the following components:
Ch17_Ex14_mainProgramI.cpp
queueADT.h
queueAsArray.h

Solution

***************************************/

Ch17_Ex14_mainProgramI.cpp

***************************************/

// Header files
#include \"queueAsArray.h\"

using namespace std;

// Main function
int main()

{

int position;

position=5; // match the example .jpg

cout << \"Enter the position of the element to be moved to the front.\" << endl;

cout <<\"15\"<<endl; //print variable of 15

cout<<endl;

cout << \"queue: \";

queueType<int> queue(5);

//stored numbers

queue.addQueue(12);

queue.addQueue(35);

queue.addQueue(45);

queue.addQueue(21);

queue.deleteQueue(); // deletes the value

queue.addQueue(14);

queue.addQueue(52);

queue.addQueue(5);

queue.addQueue(29);

queue.addQueue(10);

queue.moveNthFront(position);

while (!queue.isEmptyQueue())

{

cout << queue.front() << \" \";

queue.deleteQueue();

}

cout << endl;

cin.get();

system(\"pause\");

return 0;

}

/****************
queueAsArray.h
*****************/

#pragma

#include <iostream>
#include <vector>
#include <cassert>
#include \"queueADT.h\"

using namespace std;

template <class Type>
class queueType: public queueADT<Type>
{
public:
const queueType<Type>& operator=(const queueType<Type>&);
//Overload the assignment operator.

bool isEmptyQueue() const;
//Function to determine whether the queue is empty.
//Postcondition: Returns true if the queue is empty,
// otherwise returns false.

bool isFullQueue() const;
//Function to determine whether the queue is full.
//Postcondition: Returns true if the queue is full,
// otherwise returns false.

void initializeQueue();
//Function to initialize the queue to an empty state.
//Postcondition: count = 0; queueFront = 0;
// queueRear = maxQueueSize – 1

Type front() const;
//Function to return the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
// terminates; otherwise, the first
// element of the queue is returned.
Type back() const;
//Function to return the last element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
// terminates; otherwise, the last
// element of the queue is returned.

void addQueue(const Type& queueElement);
//Function to add queueElement to the queue.
//Precondition: The queue exists and is not full.
//Postcondition: The queue is changed and queueElement
// is added to the queue.

void deleteQueue();
//Function to remove the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: The queue is changed and the first
// element is removed from the queue.

queueType(int queueSize = 100);
//Constructor

queueType(const queueType<Type>& otherQueue);
//Copy constructor

~queueType();
//Destructor

void moveNthFront(int n);

private:
int maxQueueSize; //variable to store the maximum queue size
int count; //variable to store the number of
//elements in the queue
int queueFront; //variable to point to the first
//element of the queue
int queueRear; //variable to point to the last
//element of the queue
Type *qList; //pointer to the array that holds
//the queue elements
};

template <class Type>
bool queueType<Type>::isEmptyQueue() const
{
return (count == 0);
} //end (pg 1208)

template <class Type>
bool queueType<Type>::isFullQueue() const
{
return (count == maxQueueSize);
} //end (pg 1208)

template <class Type>
void queueType<Type>::initializeQueue()
{
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
} //(pg 1209)

template <class Type>
Type queueType<Type>::front() const
{
assert(!isEmptyQueue());
return qList[queueFront];
} //end front

template <class Type>
Type queueType<Type>::back() const
{
assert(!isEmptyQueue());
return qList[queueRear];
} //end back

template <class Type>
void queueType<Type>::addQueue(const Type& newElement)
{
if (!isFullQueue())
{   
queueRear = (queueRear + 1) % maxQueueSize;
count++;
qList[queueRear] = newElement;
}
else
cout << \"Cannot add to a full queue.\" << endl;
} // pg 1209 implementation of the addqueue

template <class Type>
void queueType<Type>::deleteQueue()
{
if (!isEmptyQueue())
{   
count--;
queueFront = (queueFront + 1) % maxQueueSize; // mod bc it is circular
}
else
cout << \"Cannot remove from an empty queue.\" << endl;
} //pg 1210
template <class Type>
queueType<Type>::queueType(int queueSize)   
{
if (queueSize <= 0)
{
cout << \"Size of the array to hold the queue must \"
<< \"be positive.\" << endl;
cout << \"Creating an array of size 100.\" << endl;

maxQueueSize = 100;
}
else
maxQueueSize = queueSize;
       queueFront = 0;   
       queueRear = maxQueueSize - 1;   
       count = 0;
       qList = new Type[maxQueueSize];
} //pg 1210

template <class Type>
queueType<Type>::~queueType()   
{
delete [] qList;
} //pg 1211

template <class Type>
const queueType<Type>& queueType<Type>::operator=
   (const queueType<Type>& otherQueue)
{
cout << \"Write the definition of the function \"
<< \"to overload the assignment operator.\" << endl;
}

template <class Type>
void queueType<Type>::moveNthFront(int y)
{
   if (count == 0)
cout << \"The queue is empty.\" << endl;
else
{
           int x = (queueFront + y - 1) % maxQueueSize;
           Type temp = qList[x];
           if (queueFront <= x)
               for (int b = x; b > queueFront; b--)
qList[b] = qList[b - 1];
else{
while (x != maxQueueSize - 1)
{
if (x == 0)
{
qList[x] = qList[maxQueueSize - 1];
x = maxQueueSize - 1;
}
else
{
qList[x] = qList[x - 1];
x--;
}
}
for (int b = x; b > queueFront; b--) qList[b] = qList[b - 1];
}
qList[queueFront] = temp;
   }
}

/************
queueADT.h
*************/

#pragma
// this class was taken from Ch 18 Stacks 6th edition page 1201
template <class Type>
class queueADT
{
public:
   virtual void initializeQueue() = 0;
// method to initialize to empty state and post:q is empty
virtual bool isEmptyQueue() const = 0;
//Function to determine whether the queue is empty.
//Postcondition: True=empty if not, false
virtual bool isFullQueue() const = 0;
//Function to determine whether the queue is full.
//Postcondition: Returns true if the queue is full
virtual Type front() const = 0;
//Function to return the first element of the queue.
virtual Type back() const = 0;
//Function to return the last element of the queue.
virtual void addQueue(const Type& queueElement) = 0;
//Function to add queueElement to the queue.
virtual void deleteQueue() = 0;
//Function to remove the first element of the queue.
};

Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than
Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than
Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than
Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than
Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than
Also if you could break it down for me like bold queueADT.h and queueAsArray.h so i know that it goes under a header file and not part of the main.CPP file than

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site