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.   HEADER FILE FOR queueAsArray.h //Header file QueueAsArray #ifndef H_QueueAsArray #define H_QueueAsArray #include #include #include "queueADT.h" using namespace std; template class queueType: public queueADT { public: const queueType& operator=(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: 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& otherQueue); //Copy constructor ~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 bool queueType::isEmptyQueue() const { return (count ==0); } //end isEmptyQueue template bool queueType::isFullQueue() const { return (count == maxQueueSize); } //end isFullQueue template void queueType::initializeQueue() { queueFront = 0; queueRear = maxQueueSize - 1; count = 0; } //end initializeQueue template Type queueType::front() const { assert(!isEmptyQueue()); return list[queueFront]; } //end front template Type queueType::back() const { assert(!isEmptyQueue()); return list[queueRear]; } //end back template void queueType::addQueue(const Type& newElement) { if (!isFullQueue()) { queueRear = (queueRear + 1) % maxQueueSize; //use mod //operator to advance queueRear //because the array is circular count++; list[queueRear] = newElement; } else cerr << "Cannot add to a full queue." << endl; } //end addQueue template void queueType::deleteQueue() { if (!isEmptyQueue()) { count--; queueFront = (queueFront + 1) % maxQueueSize; //use the //mod operator to advance queueFront //because the array is circular } else cerr << "Cannot remove from an empty queue." << endl; } //end deleteQueue //Constructor template queueType::queueType(int queueSize) { if (queueSize <=0) { cerr << "Size of the array to hold the queue must " <<"be positive."<< endl; cerr << "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::~queueType() { delete [] list; } //end destructor //Add definition for overloaded assignment operator //Add definition for copy constructor #endif

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
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 test these operations.

 

HEADER FILE FOR queueAsArray.h

//Header file QueueAsArray

#ifndef H_QueueAsArray
#define H_QueueAsArray
#include<iostream>
#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

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 <class Type>
bool queueType<Type>::isEmptyQueue() const
{
return (count ==0);
} //end isEmptyQueue

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

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

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

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

template <class Type>
void queueType<Type>::addQueue(const Type& newElement)
{
if (!isFullQueue())
{
queueRear = (queueRear + 1) % maxQueueSize; //use mod
//operator to advance queueRear
//because the array is circular
count++;
list[queueRear] = newElement;
}
else
cerr << "Cannot add to a full queue." << endl;
} //end addQueue

template <class Type>
void queueType<Type>::deleteQueue()
{
if (!isEmptyQueue())
{
count--;
queueFront = (queueFront + 1) % maxQueueSize; //use the
//mod operator to advance queueFront
//because the array is circular
}
else
cerr << "Cannot remove from an empty queue." << endl;
} //end deleteQueue

//Constructor
template <class Type>
queueType<Type>::queueType(int queueSize)
{
if (queueSize <=0)
{
cerr << "Size of the array to hold the queue must "
<<"be positive."<< endl;
cerr << "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 <class Type>
queueType<Type>::~queueType()
{
delete [] list;
} //end destructor

//Add definition for overloaded assignment operator

//Add definition for copy constructor

#endif

 

 

main.cpp
queueADT.h
queueAsArray.h
| +
28
//
terminates; otherwise, the first
29
//
element of the queue is returned.
30
virtual Type back() const =
//Function to return the last element of the queue.
31
0;
32
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
33
34
35
//
terminates; otherwise, the last
36
//
element of the queue is returned.
37
virtual void addQueue(const Type& queueElement)
//Function to add queueElement to the queue.
38
0;
39
40
//Precondition: The queue exists and is not full.
//Postcondition: The queue is changed and queueElement
is added to the queue.
41
42
//
43
virtual void deleteQueue()
= 0;
//Function to remove the first element of the queue.
44
45
46
//Precondition: The queue exists and is not empty.
47
//Postcondition: The queue is changed and the first
element is removed from the queue.
48
//
49 };
50
51
52 #endif
53
Transcribed Image Text:main.cpp queueADT.h queueAsArray.h | + 28 // terminates; otherwise, the first 29 // element of the queue is returned. 30 virtual Type back() const = //Function to return the last element of the queue. 31 0; 32 //Precondition: The queue exists and is not empty. //Postcondition: If the queue is empty, the program 33 34 35 // terminates; otherwise, the last 36 // element of the queue is returned. 37 virtual void addQueue(const Type& queueElement) //Function to add queueElement to the queue. 38 0; 39 40 //Precondition: The queue exists and is not full. //Postcondition: The queue is changed and queueElement is added to the queue. 41 42 // 43 virtual void deleteQueue() = 0; //Function to remove the first element of the queue. 44 45 46 //Precondition: The queue exists and is not empty. 47 //Postcondition: The queue is changed and the first element is removed from the queue. 48 // 49 }; 50 51 52 #endif 53
| main.cpp
queueADT.h
queueAsArray.h
3 #ifndef H_queueADT
4 #define H_queueADT
5
6 template <class Type>
7 class queueADT
8 {
9 public:
virtual bool isEmptyQueue() const = 0;
//Function to determine whether the queue is empty.
10
11
12
//Postcondition: Returns true if the queue is empty,
13
//
otherwise returns false.
14
15
virtual bool isFullQueue() const = 0;
16
//Function to determine whether the queue is full.
17
//Postcondition: Returns true if the queue is full,
18
//
otherwise returns false.
19
20
virtual void initializeQueue() = 0;
21
//Function to initialize the queue to an empty state.
22
//Postcondition: The queue is empty.
23
virtual Type front() const
//Function to return the first element of the queue.
24
0;
25
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
26
27
28
//
terminates; otherwise, the first
+
Transcribed Image Text:| main.cpp queueADT.h queueAsArray.h 3 #ifndef H_queueADT 4 #define H_queueADT 5 6 template <class Type> 7 class queueADT 8 { 9 public: virtual bool isEmptyQueue() const = 0; //Function to determine whether the queue is empty. 10 11 12 //Postcondition: Returns true if the queue is empty, 13 // otherwise returns false. 14 15 virtual bool isFullQueue() const = 0; 16 //Function to determine whether the queue is full. 17 //Postcondition: Returns true if the queue is full, 18 // otherwise returns false. 19 20 virtual void initializeQueue() = 0; 21 //Function to initialize the queue to an empty state. 22 //Postcondition: The queue is empty. 23 virtual Type front() const //Function to return the first element of the queue. 24 0; 25 //Precondition: The queue exists and is not empty. //Postcondition: If the queue is empty, the program 26 27 28 // terminates; otherwise, the first +
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY