Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
Question
Book Icon
Chapter 18, 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
C++ Programming  Requirments:  Please submit just one file for the classes and main to test the classes. Just create the classes before main and submit only one cpp file. Do not create separate header files. Please note: the deleteNode needs to initialize the *nodePtr and the *previousNode. The code to do this can be copied from here:ListNode *nodePtr, *previousNode = nullptr;   Part 1: Your own Linked ListDesign your own linked list class to hold a series of integers. The class should have member functions for appending, inserting, and deleting nodes. Don't forget to add a destructor that destroys the list. Demonstrate the class with a driver program.Part 2: List PrintModify the linked list class you created in part 1 to add a print member function. The function should display all the values in the linked list. Test the class by starting with an empty list, adding some elements, and then printing the resulting list out.
CLASSES, DYNAMIC ARRAYS AND POINTERS   Define a class called textLines that will be used to store a list of lines of text (each line can be specified as a string). Use a dynamic array to store the list.  In addition, you should have a private data member that specifies the length of the list.  Create a constructor that takes a file name as parameter, and fills up the list with lines from the file.  Make sure that you set the dynamic array to expand large enough to hold all the lines from the file.  Also, create a constructor that takes an integer parameter that sets the size of an empty list. in C++   Write member functions to: remove and return the last line from the list add a new line onto the end of the list, if there is room for it, otherwise print a message and expand the array empty the entire list return the number of lines still on the list take two lists and return one combined list (with no duplicates) copy constructor to support deep copying remember the destructor!
C# Programing Language Given the code below 1.Change all of the low-level arrays in your program to use the appropriate C# collection class instead. Be sure to implement Deck as a Stack 2. Make sure that you use the correct type-safe generic designations throughout your program. 3.Write code that watches for that incorrect data and throws an appropriate exception if bad data is found.4. Write Properties instead of Getter and Setter methods. no lamdas, no delegates, no LINQ, no eventsGo Fish using System; namespace GoFish{public enum Suit { Clubs, Diamonds, Hearts, Spades };public enum Rank { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King }; // ----------------------------------------------------------------------------------------------------- public class Card{public Rank Rank { get; private set; }public Suit Suit { get; private set; } public Card(Suit suit, Rank rank){this.Suit = suit;this.Rank = rank;} public override string ToString(){return ("[" +…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education