In this assignment, we want to implement a class for Queue data structure. You should be familiar with queues from your first assignment where you implemented a simple queue class. Here, we focus on a...

In this assignment, we want to implement a class for Queue data structure. You should be familiar with queues from your first assignment where you implemented a simple queue class. Here, we focus on a more complex and capable implementation of queues. This assignment covers the topics of dynamic memory allocation, template classes, exception handling, and operator handling. 1- Queue A queue is an abstract data type which keeps a collection of entities. Queue is a First-In-First-Out (FIFO) data structure and the first element added to the queue would be the first to be removed. You can read more about queues in the following public link

: https://computersciencewiki.org/index.php/Queue


 2- Implementation


You need to implement a template class for the queue data type. In the following you can see a set of requirements and explanations for your implementation:


• You should implement the queue using dynamic array.


• You are NOT allowed to use std::vector or any other built-in array-like classes to implement the queue. • Your queue must be capable of holding different datatypes like int, double, char, or even other classes (although all the elements will have the same data type).


• The queue must always know itssize, named Qsize, and you must have a member function that returns this size, call this function getSize().


• You also need a default constructor without any input parameters which must create a queue of size zero.


 • You also need to implement a copy constructor which gets a const Queue& yourQueue as its input parameter and creates a new queue object which is a copy of the input one. • You must allocate memory dynamically.


• Your queue class must be able to enqueue and dequeue objects to the queue. So, you should implement the related methods. These methods should obviously resize your queue. You are responsible for implementing this resizing. So, for each enqueue you need to allocate a new array of size (Qsize+1) and copy everything from the old array to the new one. For dequeue, you follow a set of similar steps with size (Qsize-1). Take care of dangling pointers and memory leak.


• You need to handle possible exceptions, especially when working with dynamic memory. For example, you obviously need such exception handling when trying to enqueue a new object to the queue. • You need to write the appropriate destructor for your queue class.


• You also need to implement a function called isEmpty() which returns true if the queue is empty and false if the queue is not empty.


• You should override the assignment operator for the objects of your class to make it possible to assign one object of your queue class to another like this: Queue myqueue1; Queue myqueue2; myqueue1 = myqueue2;


• You should also overload the <><>


• You need to overload the subscript operator ([]) for objects of your class which makes it possible to access an element in the queue if it really exists. This is just for accessing (getting) an element but not for assigning a new element to the queue which is only possible with the enqueue function. Example: Queue myqueue1; std::cout <>


• This is not a linked list assignment. You are not allowed to implement this queue as a linked list. • Your program must not have memory leak and dangling pointers.


• We will create objects of you queue class for different datatypes and test the required functionalities.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here