EBK STARTING OUT WITH C++ FROM CONTROL
EBK STARTING OUT WITH C++ FROM CONTROL
9th Edition
ISBN: 8220106714379
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
Hands-On Assignments Part II Assignment 1-5: Querying the DoGood Donor Database Review the DoGood Donor data by writing and running SQL statements to perform the following tasks: 1. List each donor who has made a pledge and indicated a single lump sum payment. Include first name, last name, pledge date, and pledge amount. 2. List each donor who has made a pledge and indicated monthly payments over one year. Include first name, last name, pledge date, and pledge amount. Also, display the monthly payment amount. (Equal monthly payments are made for all pledges paid in monthly payments.) 3. Display an unduplicated list of projects (ID and name) that have pledges committed. Don't display all projects defined; list only those that have pledges assigned. 4. Display the number of pledges made by each donor. Include the donor ID, first name, last name, and number of pledges. 5. Display all pledges made before March 8, 2012. Include all column data from the DD PLEDGE table.
Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2)…
Find the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday',                     'Wednesday', 'Thursday', 'Friday',                     'Saturday'] for i in range(7):         daily_sales[i] = float(input('Enter the sales for ' \                                      + day_of_week[i] + ': ')
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning