Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 7PC
Program Plan Intro
Queue Exceptions
“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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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
Chapter 18 Solutions
Starting Out with C++: Early Objects
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PC
Knowledge Booster
Similar questions
- C++ Code for a QueueThe program should features a Queue class with insert(), remove(), peek(),isFull(), isEmpty(), and size() member functions.The main() program creates a queue of five cells, inserts four items, removes threeitems, and inserts four more. The sixth insertion invokes the wraparound feature. All the items are then removed and displayed. The output looks like this:40 50 60 70 80arrow_forwardc++ Write a client function that returns the back of a queue while leaving the queue unchanged. This function can call any of the methods of the ADT queue. It can also create new queues. The return type is ITemType, and it accepts a queue as a parameter.arrow_forwardLanguage: C++ Note: Write both parts separately. Part a: Complete the above Priority Queue class. Write a driver to test it. Part b: Modify the above class to handle ‘N’ different priority levelsarrow_forward
- for c++ thank you Error Testing The DynIntStack and Dyn IntQueue classes shown in this chapter are abstract data types using a dynamic stack and dynamic queue, respectively. The classes do not cur- rently test for memory allocation errors. Modify the classes so they determine whether new nodes cannot be created by handling the bad_alloc exception. here is the extention.h file please use it #ifndef DYNINTQUEUE_H #define DYNINTQUEUE_H class DynIntQueue { private: // Structure for the queue nodes struct QueueNode { int value; // Value in a node QueueNode *next; // Pointer to the next node }; QueueNode *front; // The front of the queue QueueNode *rear; // The rear of the queue int numItems; // Number of items in the queue public: // Constructor DynIntQueue(); // Destructor ~DynIntQueue(); // Queue operations void enqueue(int); void dequeue(int &); bool isEmpty() const; bool isFull() const; void…arrow_forwardIn C, members (fields) of different structures can have the same name. True Falsearrow_forwardc++ a Queue Class that allows users to push strings or integer values into it. For example, when running the following code: SpecialQueue Q; Q.push("Albert"); Q.push("Jose"); Q.push(123); Q.pop(); Q.pop(); Q.pop(); The output should be: Albert Jose 123 Submit a TEXT file that contains your class. By class, I mean everything EXCEPT your main function. DO NOT SUBMIT YOUR MAIN().arrow_forward
- c++ code Screenshot and output is mustarrow_forwardStack:#ifndef STACKTYPE_H_INCLUDED#define STACKTYPE_H_INCLUDEDconst int MAX_ITEMS = 5;class FullStack// Exception class thrown// by Push when stack is full.{};class EmptyStack// Exception class thrown// by Pop and Top when stack is emtpy.{};template <class ItemType>class StackType{public:StackType();bool IsFull();bool IsEmpty();void Push(ItemType);void Pop();ItemType Top();private:int top;ItemType items[MAX_ITEMS];};#endif // STACKTYPE_H_INCLUDED Queue:#ifndef QUETYPE_H_INCLUDED#define QUETYPE_H_INCLUDEDtemplate<class T>class QueType{public:QueType();QueType(int);~QueType();void MakeEmpty();bool IsEmpty();bool IsFull();void Enqueue(T);void Dequeue(T&);T Front();private:int front;int rear;T *info;int maxQue;};#endif // QUETYPE_H_INCLUDEDarrow_forward1. Answer YES or NO to the following: Would it make sense to call a queue? a) a LILO structure? b) a FILO structure? 2. What is the main advantage of implementing a queue using a linked list rather than an array? 3. Indicate if the java.util.PriorityQueue method returns an exception, null, or false. a) poll() b) offer() c) peek() d) remove() e) element()arrow_forward
- Note : It is required to done this by oop in C++. Create a queue, size of queue will be dependent on the user. Insert the numbers in the queue till the queue reaches the size. Create a menu and perform the following function on that queue. Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the front of the queue IsEmpty: Check if the queue is empty IsFull: Check if the queue is full Peek: Get the value of the front of the queue without removing itarrow_forwardQ1: Write a java application for the stack operations with Linked List. Q2: Write java program to take the order from the customer and display the ordered items and total payment. If customer is entering the wrong name or not following the order to enter the menu it has to display error messages. (Find in the sample code) Sample Output:arrow_forward1)Write a Java program which stores three values by using singly linked list.- Node class1. stuID, stuName, stuScore, //data fields2. constructor3. update and accessor methods- Singly linked list class which must has following methods:1. head, tail, size// data fields2. constructor3. update and accessor methodsa. getSize() //Returns the number of elements in the list.b. isEmpty( ) //Returns true if the list is empty, and false otherwise.c. getFirstStuID( ), getStuName( ), getFirstStuScore( )d. addFirst(stuID, stuName, stuScore)e. addLast(stuID, stuName, stuScore)f. removeFirst ( ) //Removes and returns the first element of the list.g. displayList( ) //Displays all elements of the list by traversing the linked list.- Test class – initialize a singly linked list instance. Test all methods of singly linked list class. 2. Write a Java program which stores three values by using doubly linked list.- Node class4. stuID, stuName, stuScore, //data fields5. constructor6. update and…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education