Question: 1) C++: Write the definition of the function moveNthFront that takes as a parameter a positive integer, n. The function moves the nth element of
1) C++: Write the definition of the function moveNthFront that takes as a parameter 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
So here is my main class (Ch17_Ex14_mainProgramI.cpp):
#include "QueueAsArray.h"
#include
using namespace std;
int main()
{
queueType myQueue(100);
int n;
for (int i = 1; i < 10; i++)
myQueue.addQueue(i);
cout << " The elements in the queue were : ";
myQueue.print();
cout << " Enter element's position to move : ";
cin >> n;
myQueue.moveNthFront(n);
cout << " \tThe elements in the queue after move were: ";
myQueue.print();
system("pause");
return 0;
}
For the life of me I can't figure out how to get the other two classes to work for me. Any help you can give for queueADT.h and queueAsArray.h
Here are my two classes:
queueADT.h
#ifndef H_queueADT
#define H_queueADT
template
class queueADT
{
public:
virtual bool isEmptyQueue() const = 0;
//Function to determine whether the queue is empty.
//Postcondition: Returns true if the queue is empty,
// otherwise returns false.
virtual bool isFullQueue() const = 0;
//Function to determine whether the queue is full.
//Postcondition: Returns true if the queue is full,
// otherwise returns false.
virtual void initializeQueue() = 0;
//Function to initialize the queue to an empty state.
//Postcondition: The queue is empty.
virtual Type front() const = 0;
//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.
virtual Type back() const = 0;
//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.
virtual void addQueue(const Type& queueElement) = 0;
//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.
virtual void deleteQueue() = 0;
//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.
};
#endif
queueAsArray.h
#ifndef H_QueueAsArray
#define H_QueueAsArray
#include
#include
#include "queueADT.h"
using namespace std;
template
class queueType : public queueADT
{
public:
const queueType
//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: The queue is empty.
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
//Copy constructor
~queueType();
//Destructor
void moveNthFront(int n);
//the queue elements
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 *list; //pointer to the array that holds
};
template
bool queueType
{
return (count == 0);
} //end isEmptyQueue
template
bool queueType
{
return (count == maxQueueSize);
} //end isFullQueue
template
void queueType
{
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
} //end initializeQueue
template
Type queueType
{
assert(!isEmptyQueue());
return list[queueFront];
} //end front
template
Type queueType
{
assert(!isEmptyQueue());
return list[queueRear];
} //end back
template
void queueType
{
if (!isFullQueue())
{
queueRear = (queueRear + 1) % maxQueueSize; //use mod
//operator to advance queueRear
//because the array is circular
count++;
list[queueRear] = newElement;
}
else
cout << "Cannot add to a full queue." << endl;
} //end addQueue
template
void queueType
{
if (!isEmptyQueue())
{
count--;
queueFront = (queueFront + 1) % maxQueueSize; //use the
//mod operator to advance queueFront
//because the array is circular
}
else
cout << "Cannot remove from an empty queue." << endl;
} //end deleteQueue
//Constructor
template
queueType
{
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; //set maxQueueSize to
//queueSize
queueFront = 0; //initialize queueFront
queueRear = maxQueueSize - 1; //initialize queueRear
count = 0;
list = new Type[maxQueueSize]; //create the array to
//hold the queue elements
} //end constructor
//Destructor
template
queueType
{
delete[] list;
} //end destructor
template
const queueType
(const queueType
{
cout << "Write the definition of the function "
<< "to overload the assignment operator." << endl;
} //end assignment operator
template
queueType
{
cout << "Write the definition of the copy constructor."
<< endl;
} //end copy constructor
template
void queueType
{
int i, i1, i2;
Type tmp;
for (i = queueFront + n - 1; i > queueFront; i--)//keep swapping from nth to front element
{
i1 = i % maxQueueSize;//first element
i2 = (i - 1) % maxQueueSize;//second element
//swap both
tmp = list[i1];
list[i1] = list[i2];
list[i2] = tmp;
}
}
#endif
-----------------------------------------------------
What did I do wrong for the other two classes that I have an error that says "class "queueType
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
