Question: Write the definitions of the functions to overload the assignment operator and copy constructor for the class queueType. Also, write a program (in main.cpp) to
Write the definitions of the functions to overload the assignment operator and copy constructor for the class queueType. Also, write a program (in main.cpp) to test these operations.
the given classes are:
queueADT.h
//Header file: queueADT.h
#ifndef H_queueADT #define H_queueADT template
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
and queueAsArray.h
//Header file QueueAsArray
#ifndef H_QueueAsArray #define H_QueueAsArray #include
#include "queueADT.h"
using namespace std;
template
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
~queueType(); //Destructor
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 //the queue elements };
template
template
template
template
template
template
template
//Constructor template
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
//Add definition for overloaded assignment operator
//Add definition for copy constructor
#endif
make sure:
2 queues of type queueType are declared in the main
addQueue is called in main to test the operations
deletequeue is called in main to test the operations
front is called in amin to test the operations
isEmptyQueue is called in main to test operations
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
