Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: SAVITCH
Publisher: PEARSON
Question
Book Icon
Chapter 16, Problem 5PP
Program Plan Intro

  • Include required library files.
  • Define a class named “StackOverflowException”.
    • Inside the access specifier “public”,
      • Define a constructor to assign the message
      • Declare a parameterized constructor to assign “msg” to message.
      • Define a function “display” to return message.
    • Inside the access specifier “private”.
      • Declare a string variable “message”.
  • Define a class named “StackEmptyException”.
    • Inside the access specifier “public”,
      • Define a constructor to assign the message
      • Declare a parameterized constructor to assign “msg” to message.
      • Define a function “display” to return message.
    • Inside the access specifier “private”.
      • Declare a string variable “message”.
  • Define a class named “Stack”.
    • Declare an integer array and variable.
    • Inside the access specifier “public”,
      • Define a constructor to assign “-1” to “top”.
      • Define a “push()” function.
        • “try” block to check the top is equal to “3”.
          • The condition is true, throw exception.
          • Otherwise increment the top and the value is assigned to stack.
        • “catch” block to display the error message.
      •  Define a “pop()” function.
        • “try” block to check the top is equal to “-1”.
          • The condition is true, throw exception.
        • Otherwise decrement the top and return the value.
        • “catch” block to display the error message.
  • Define a “main()” function.
    • Create an object for class “Stack”.
    • Then check the “push()” and “pop()” function.

Blurred answer
Students have asked these similar questions
ADT stack lets you peek at its top entry without removing it. For some applications of stacks, youalso need to peek at the entry beneath the top entry without removing it. We will call such an operationpeekNxt. If the stack has more than one entry, peekNxt returns the second entry from the top without altering the stack. If the stack has fewer than two entries, peekNxt throws an exception. Write a linkedimplementation of a stack class call LinkedStack.java that includes a method peekNxt.   Please make sure that this is included in peekNxt:  If the stack has fewer than two entries, peekNxt throws an exception and if you could please make a main to execute peekNxt, thank you.There are 2 class, 1 with the peekNxt, and 1 for implementation. You only need to work on the first one with the peekNxt in it         import java.util.EmptyStackException;import java.util.NoSuchElementException;public final class LinkedStack<T> implements StackInterface<T>{private Node topNode;…
Create a TestStack project. Add a Stack class with all of the methods implemented and commented (constructor, push, pop, is empty, clear, peek, toString). Create a TestStack class with main(). main() should use your Stack class to do one of the following: OPTION A) Use your stack class to reverse a user inputted string. A palindrome is a word that reads the same backwards as it does forwards. For example, madam is a palindrome, hello is not. Use your stack class to test if an input string is a palindrone or not. OPTION B) Use your new Stack to add a function that checks for balanced parenthese in an equation. Use these three equations, plus one of your own to test your code. ((3^2 + 8)*(5/2))/(2+6) ((3^2 + 8)*(5/2))/(2+6)) (((3^2 + 8)*(5/2)/(2+6) When encountering a left parenthese, push it on the stack. Pop one off when you encounter a right parenthese. Return true or false depending if parentheses are balanced or not (stack is empty after last right parenthese causes a…
Stack:#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_INCLUDED
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning