STARTING OUT W/C++,...(LL)-W/ACCESS
STARTING OUT W/C++,...(LL)-W/ACCESS
9th Edition
ISBN: 9780134596174
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 8PC
Program Plan Intro

Dynamic MathStack Template

Program Plan:

MathStack.h:

  • Include required header files
  • Declare a class named “MathStack” which inherits “DynStack” Inside the class,
    • Inside “public” access specifier,
      • Declare functions “add ()”, “sub ()”, “mult ()”, “div ()”, “addAll ()”, and “multAll ()”.
  • Declare class template.
  • Give function definition to add elements “add ()”.
    • Declare required template variables “num_Value”, and “sum_Value”.
    • Call the function “pop ()”
    • Add the elements.
    • Push the value into the stack using the function “push ()”.
  • Declare class template.
  • Give function definition to subtract elements “sub ()”.
    • Declare required template variables “num_Value”, and “diff_Value”.
    • Call the function “pop ()”
    • Subtract the elements.
    • Push the value into the stack using the function “push ()”.
  • Declare class template.
  • Give function definition to multiply elements “mult ()”.
    • Declare required template variables “num_Value”, and “prod_Value”.
    • Call the function “pop ()”
    • Multiply the elements.
    • Push the value into the stack using the function “push ()”.
  • Declare class template.
  • Give function definition to divide elements “div ()”.
    • Declare required template variables “num_Value”, and “quo_Value”.
    • Call the function “pop ()”
    • Divide the elements.
    • Push the value into the stack using the function “push ()”.
  • Declare class template.
  • Give function definition to add all the elements “addAll ()”.
    • Declare required template variables “num_Value”, and “sum_Value”.
    • Call the function “pop ()”
    • Add all the elements.
    • Push the value into the stack using the function “push ()”.
  • Declare class template.
  • Give function definition to multiply all the elements “multAll ()”.
    • Declare required template variables “num_Value”, and “prod_Value”.
    • Call the function “pop ()”
    • Multiply all the elements.
    • Push the value into the stack using the function “push ()”.

DynStack.h:

  • Include required header files.
  • Create a template.
  • Declare a class named “DynStack”. Inside the class
    • Inside the “protected” 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”
      • Declare a variable named “stackSize”.
    • 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.
  • Give 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.
  • Give 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 node and make temp as the top node.
  • Give the class template.
  • Give function definition for “isEmpty ()”.
    • Assign false to a Boolean variable
    • Check if the top node is null
      • Assign true to “status”.
    • Return the status

Main.cpp:

  • Include required header files.
  • Inside “main ()” function,
    • Declare constant variables “STACKSIZE”, “ADDSIZE”, and “MULTSIZE”.
    • Create three stacks “stack”, “addAllStack”, and “multAllStack”.
    • Declare two variables “popVar” and “ipopVar”.
    • Push two elements to perform add operation.
    • Call the function “add ()”.
    • Display the element.
    • Push two elements to perform multiplication operation.
    • Call the function “mult ()”.
    • Display the element.
    • Push two elements to perform division operation.
    • Call the function “div ()”.
    • Display the element.
    • Push two elements to perform subtraction operation.
    • Call the function “sub ()”.
    • Display the element.
    • Push four elements to perform addAll operation.
    • Call the function “addAll ()”.
    • Display the element.
    • Push six elements to perform multAll operation.
    • Call the function “multAll ()”.
    • Display the element.

Blurred answer
Students have asked these similar questions
Please original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinks
Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinks
What is cloud computing and why do we use it? Give one of your friends with your answer.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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