Question: Modify the static queue class used in Program 18-5 as follows: 1. Make the isFull member private. 2. Define a queue overflow exception and modify

Modify the static queue class used in Program 18-5 as follows:

1. Make the isFull member 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 tht it throws this exception when the queue is empty.

4. Rewrite the main program so that it catches overflow rxceptions when they occur. The exception handler for queue overflow should print an appropriate error message andthen terminate the program.

PROGRAM 18-5:

//This program demonstrates the IntQueue class.

#include

#include "IntQueue.h"

using namespace std;

int main()

{

IntQueue iQueue(5);

cout << "Enqueuing 5 items... ";

//Enquieing 5 items

fo (int k =1; k<=5; k++)

IQueue.enqueue(k*k);

//Deqeue and retrieve all items in the queue

cout << "The values in the queue were: ";

while (!iQueue.isEmpty()))

{

int value;

iQueue.dequeue(value);

cout << value << " " ;

}

cout << endl;

return 0;

}

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!