Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***********************************Please Edit the .cpp and the .h files using the directions above in 5 and 7**************************** #ifndef CLASS_18_2_H_INCLUDED #define CLASS_18_2_H_INCLUDED #include using namespace std; template

image text in transcribed

***********************************Please Edit the .cpp and the .h files using the directions above in 5 and 7****************************

#ifndef CLASS_18_2_H_INCLUDED #define CLASS_18_2_H_INCLUDED

#include using namespace std; template class DyIntStack { private: struct Node { Template value; Node *next; }; Node *top; public: DyIntStack( ) { top = NULL; } ~DyIntStack();

bool Empty(); void push(Template); void pop(Template &); }; //*************************************************************** template bool DyIntStack::Empty() { bool status; if (!top) status = true; else status = false; return status; } //*************************************************************** template DyIntStack::~DyIntStack() { Node *nodePtr, *nxtNode; nodePtr = top;

while (nodePtr != NULL) { nxtNode = nodePtr->next; delete nodePtr; nodePtr = nxtNode; } } //*************************************************************** template void DyIntStack::push(Template n) { Node *NN; NN = new Node; NN->value = n;

if (Empty()) { top = NN; NN->next = NULL; } else { NN->next = top; top = NN; } } //*************************************************************** template void DyIntStack::pop(Template &n) { Node *temp; if (Empty()) { cout value; temp = top->next; delete top; top = temp; } }

#endif

--------------------------------------------------------------------.cpp file below and .h file above-------------------------------------------------------------------------

#include #include "class_18.2.h"

using namespace std; int main() { int holdv; char holdv1;

DyIntStack stack; DyIntStack stack1;

cout

cout

cout

cout 5. Error Testing The DynIntstack and DynIntQueue classes shown in this chapter are abstract data types using a dynamic stack and dynamic queue, respectively. The classes do not currently test for memory allocaton errors. Modify the classes so they determine if new nodes cannot be created, and handle the error condition in an appropriate way. (You will need to catch the predefined exception bad_alloc.) NOTE: If you have already done Programming Challenges 2 and 4, modify the templates you created. 7. Queue Exceptions Modify the static queue class used in Program 18-5 as follows. Make the isFull member private. tion when the queue runs out of space. tion when the queue is empty. The exception handler for queue overflow should print an appropriate error message 1. 2. Define a queue overflow exception and modify enqueue so that it throws this excep- 3. Define a queue underflow exception and modify dequeue so that it throws this excep- 4. Rewrite the main program so that it catches overflow exceptions when they occur. and then terminate the program

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago