Make the isFull and isEmpty member functions private. Define a queue overflow exception and modify enqueue so that it throws this exception when the queue runs out of space. Define a queue underflow exception and modify dequeue so that it throws this exception when the queue is empty. 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. Here's the code so far: 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 << "The queue is full.\n"; 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 << "The queue is empty.\n"; 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 < queueSize) 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; } main: // This program demonstrates the IntQeue class #include #include "Data.h" using namespace std; int main() { IntQueue iQueue(5); cout << "Enqueuing 5 items...\n"; // Enqueue 5 items. for (int x = 0; x < 5; x++) iQueue.enqueue(x); // Attempt to enqueue a 6th item. cout << "Now attempting to enqueue again...\n"; iQueue.enqueue(5); // Deqeue and retrieve all items in the queue cout << "The values in the queue were:\n"; while (!iQueue.isEmpty()) { int value; iQueue.dequeue(value); cout << value << endl; } }

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
100%
Queue Exceptions: Modify the static queue class provided in our lecture as follows.
  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.

    Here's the code so far:

    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 <iostream>
    #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 << "The queue is full.\n";
    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 << "The queue is empty.\n";
    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 < queueSize)
    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;
    }


    main:

    // This program demonstrates the IntQeue class
    #include <iostream>
    #include "Data.h"
    using namespace std;

    int main()
    {
    IntQueue iQueue(5);

    cout << "Enqueuing 5 items...\n";
    // Enqueue 5 items.
    for (int x = 0; x < 5; x++)
    iQueue.enqueue(x);

    // Attempt to enqueue a 6th item.
    cout << "Now attempting to enqueue again...\n";
    iQueue.enqueue(5);

    // Deqeue and retrieve all items in the queue
    cout << "The values in the queue were:\n";
    while (!iQueue.isEmpty())
    {
    int value;
    iQueue.dequeue(value);
    cout << value << endl;
    }
    }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

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