Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
Chapter 19, Problem 5PC
Program Plan Intro

Error Testing

Dynamic Stack:

Program Plan:

Main.cpp:

  • Include required header files.
  • Inside the “main ()” function,
    • Create an object named “dstack” for stack.
    • Declare a variable named “popElem”.
    • Push 3 elements inside the stack using the function “push ()”.
    • Pop 3 elements from the stack using the function “pop ()”.

DynIntStack.h:

  • Include required header files.
  • Create a template.
  • Declare a class named “DynIntStack”. Inside the class
    • Inside the “private” access specifier,
      • Give structure declaration for the stack
        • Create an object for the template
        • Create a stack pointer name “next”.
      • Create a stack pointer name “top”
    • Inside the “public” access specifier,
      • Give a declaration for a constructor.
        • Assign null to the top node.
      • Give function declaration for “push ()”, “pop ()”,and “isEmpty ()”.
  • Give the class template.
  • Define function definition for “push ()”.
    • Assign null to the new node.
    • Dynamically allocate memory for new node,
    • Assign “num” to the value of new node.
    • Check if the stack is empty using the function “isEmpty ()”
      • If the condition is true then assign new node as the top and make the next node as null.
      • If the condition is not true then, assign top node to the next of new node and assign new node as the top.
  • Give the class template.
  • Define function definition for “pop ()”.
    • Assign null to the temp node.
    • Check if the stack is empty using the function “is_Empty ()”
      • If the condition is true then print “The stack is empty”.
      • If the condition is not true then,
        • Assign top value to the variable “num”.
        • Link top of next node to temp node.
        • Delete the top most node and make temp as the top node.
  • Define function definition for “isEmpty ()”.
    • Assign Boolean value to the variable
    • Check if the top node is null
      • Assign true to “status”.
    • Return the status

Blurred answer
Students have asked these similar questions
Stack: Stacks are a type of container with LIFO (Last In First Out) type of working, where a new element is added at one end and (top) an element is removed from that end only. Your Stack should not be of the fixed sized. It should be able to grow itself. So using the class made in task 1, make a class named as Stack, having following additional functionalities: bool empty() : Returns whether the Stack is empty or not. Time Complexity should be: O(1) bool full() : Returns whether the Stack is full or not. Time Complexity should be: O(1)int size() : Returns the current size of the Stack. Time Complexity should be: O(1)Type top () : Returns the last element of the Stack. Time Complexity should be: O(1) void push(Type) : Adds the element of type Type at the top of the stack. Time Complexity    should be: O(1) Type pop() : Deletes the top most element of the stack and returns it. Time Complexity    should be: O(1) Write non-parameterized constructor for the above class. Write Copy…
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…
1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List. 2 The data members should be private. 3 You need to implement the following public functions: 4 1. Constructor: 5 It initialises the data members as required. 6 7 8 2. enqueue(data) : This function should take one argument of type integer. It enqueues the element into the queue and returns nothing. 3. dequeue(): It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r 4. front (): 10 11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1. 12 5. getSize(): 13 It returns the size of the queue at any given instance of time. 14 6. 1sEmpty(): 15 It returns a boolean value indicating whether the queue is empty or not. 16 Operations Performed on the Stack: 17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue. 18 19 Query-2…

Chapter 19 Solutions

Starting Out with C++ from Control Structures to Objects (9th Edition)

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