Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SOLUTION REQUIRED WITH THE CONCEPT OF OBJECT ORIENTED PROGRAMMING ( OOP ) IN C++ WITHOUT ERRORS. Add exceptions to the queue template in Exercise 2.

SOLUTION REQUIRED WITH THE CONCEPT OF OBJECT ORIENTED PROGRAMMING ( OOP ) IN C++ WITHOUT ERRORS.

Add exceptions to the queue template in Exercise 2. Throw two exceptions: one if the capacity of the queue is exceeded, the other if the program tries to remove an item from an empty queue. One way to handle this is to add a new data member to the queue: a count of the number of items currently in the queue. Increment the count when you insert an item, and decrement it when you remove an item. Throw an exception if this count exceeds the capacity of the queue, or if it becomes less than 0.

You might try making the main( ) part of this exercise interactive, so the user can put values on a queue and take them off. This makes it easier to exercise the queue. Following an exception, the program should allow the user to recover from a mistake without corrupting the contents of the queue.

EXERCISE 2 QUESTION FOR REFERENCE...

A queue is a data-storage device. Its like a stack, except that, instead of being last-infirst-out, its first-in-first-out, like the line at a bank tellers window. If you put in 1, 2, 3, you get back 1, 2, 3 in that order. A stack needs only one index to an array (top in the STAKARAY program in Chapter 7). A queue, on the other hand, must keep track of two indexes to an array: one to the tail, where new items are added, and one to the head, where old items are removed. The tail follows the head through the array as items are added and removed. If either the tail or the head reaches the end of the array, it is reset to the beginning. Write a class template for a queue class. Assume that the programmer using the queue wont make any mistakes, like exceeding the capacity of the queue or trying to remove an item when the queue is empty. Define several queues of different data types and insert and remove data from them.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Why could the Robert Bosch approach make sense to the company?

Answered: 1 week ago