Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
Question
Book Icon
Chapter 18, Problem 7PC
Program Plan Intro

Queue Exceptions

Program Plan:

“main.cpp”:

  • This program features queues that can throw exceptions and print an appropriate error message and should terminate the program.
  • Include the required header files.
  • Prompt the user to enqueue 5 items.
  • Use of try – catch exceptional handling that returns error message and terminates the program if the queue overflows.
  • Prompt the user and allow user option to overflow the queue and dequeue the queue and print the values present in the queue.

“IntQueue.h”:

  • Include all the required header files.
  • Declare all the variables present in the queue along with their data types.
  • Declare all the function definition.
  • Declare the class underflow and overflow to check for exceptional handling in queue.

“IntQueue.cpp”:

  • Include all the required header files.
  • Call a constructor to create a queue and initialize its elements.
  • Initialize front and rear each to -1 and the number of elements initially present to 0.
  • A destructor is called to delete the queue array.
  • Define a queue function enqueue that inserts the value in variable num at the rear of the queue.
  • Define a queue function dequeue that deletes the value at the front of the queue, and copies it into variable.
  • Define a queue function isEmpty returns true if the queue is empty, and false if elements are present in the queue.
  • Define a Queue function is Full return true if queue is full and false if queue is not full.

Blurred answer
Students have asked these similar questions
Queue Exceptions: Modify the static queue class provided in our lecture as follows. 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.
In C++ Please
C++ language
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education