Question: aaajdjdhdjdjsj uqjqj //main // This program demonstrates the IntQeue class #include #include Data.h using namespace std; int main() { IntQueue iQueue(5); cout // Enqueue 5

aaajdjdhdjdjsjuqjqjaaajdjdhdjdjsjuqjqj //main // This program demonstrates the IntQeue class #include #include "Data.h"

using namespace std; int main() { IntQueue iQueue(5); cout // Enqueue 5

items. for (int x = 0; x iQueue.enqueue(x); // Attempt to enqueue

a 6th item. cout iQueue.enqueue(5); // Deqeue and retrieve all items in

the queue cout while (!iQueue.isEmpty()) { int value; iQueue.dequeue(value); cout } }

--------------------------- //data.h #pragma once class IntQueue { private: int *queueArray; int queueSize;

//main

// This program demonstrates the IntQeue class

#include

#include "Data.h"

using namespace std;

int main()

{

IntQueue iQueue(5);

cout

// Enqueue 5 items.

for (int x = 0; x

iQueue.enqueue(x);

// Attempt to enqueue a 6th item.

cout

iQueue.enqueue(5);

// Deqeue and retrieve all items in the queue

cout

while (!iQueue.isEmpty())

{

int value;

iQueue.dequeue(value);

cout

}

}

---------------------------

//data.h

#pragma once

class IntQueue

{

private:

int *queueArray;

int queueSize;

int front;

int rear;

int numItems;

public:

IntQueue(int);

~IntQueue();

void enqueue(int);

void dequeue(int &);

bool isEmpty();

bool isFull();

void clear();

};

-----------------------

//implementation

#include

#include "Data.h"

using namespace std;

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

// Constructor *

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

IntQueue::IntQueue(int s)

{

queueArray = new int[s];

queueSize = s;

front = -1;

rear = -1;

numItems = 0;

}

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

// Destructor *

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

IntQueue::~IntQueue()

{

delete [] queueArray;

}

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

// Function enqueue inserts the value in num *

// at the rear of the queue. *

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

void IntQueue::enqueue(int num)

{

if (isFull())

cout

else

{

// Calculate the new rear position

rear = (rear + 1) % queueSize;

// Insert new item

queueArray[rear] = num;

// Update item count

numItems++;

}

}

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

// Function dequeue removes the value at the *

// front of the queue, and copies t into num. *

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

void IntQueue::dequeue(int &num)

{

if (isEmpty())

cout

else

{

// Move front

front = (front + 1) % queueSize;

// Retrieve the front item

num = queueArray[front];

// Update item count

numItems--;

}

}

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

// Function isEmpty returns true if the queue *

// is empty, and false otherwise. *

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

bool IntQueue::isEmpty()

{

bool status;

if (numItems)

status = false;

else

status = true;

return status;

}

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

// Function isFull returns true if the queue *

// is full, and false otherwise. *

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

bool IntQueue::isFull()

{

bool status;

if (numItems

status = false;

else

status = true;

return status;

}

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

// Function clear resets the front and rear *

// indices, and sets numItems to 0. *

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

void IntQueue::clear()

{

front = queueSize - 1;

rear = queueSize - 1;

numItems = 0;

}

Problem 2 (Queues) Queue Exceptions: Modify the static queue class provided in our lecture as follows. i 1. Make the isFull and isEmpty member functions private. 2. Define a queue overflow exception and modify enqueue so that it throws this exception when the queue runs out of space. 3. Define a queue underflow exception and modify dequeue so that it throws this exception when the queue is empty. 4. Rewrite the main program so that it catches overflow exceptions when they occur. The exception handler for queue overflow should print an appropriate error message and then terminate the program. Main.cpp Data.h Implementatio... // This program demonstrates the IntQeue class 2. #include 3 #include "Data.h" 4 using namespace std; 5 6 int main() 7. { IntQueue Queue (5); 9 10 cout #include "Data.h" using namespace std; 4 5 //***** // Constructor 7 //******* IntQueue: : IntQueue (int s) 9. { 10 queueArray = new int[s]; 11 queueSize = s; 12 front = -1; 13 rear = -1; 14 numItems = 0; } 16 17 //***** 18 // Destructor 19 //****** 20 21 IntQueue: : -IntQueue 22 { 23 delete [] queueArray; 24 } 15 N N N 25 26 27 28 //****** // Function enqueue inserts the value in num * // at the rear of the queue. //******* 29 ) ) ) ) W w w w w w w w w 0 UNFO void IntQueue::enqueue (int num) { if (isFull) cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!