Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18, Problem 7PC
Program Plan Intro
Dynamic MathStack
Program Plan:
MathStack.h:
- Include required header files
- Declare a class named “MathStack”. Inside the class,
- Inside “public” access specifier,
- Declare functions “add ()”, “sub ()”, “mult ()”, “div ()”, “addAll ()”, and “multAll ()”.
- Inside “public” access specifier,
MathStack.cpp:
- Include required header files.
- Give function definition to add elements “add()”.
- Declare required variables “number”, and “sum_Value”.
- Call the function “pop()”.
- Add the elements.
- Push the value into the stack using the function “push()”.
- Give function definition to subtract elements “sub()”.
- Declare required variables “number”, and “diff_Value”.
- Call the function “pop()”.
- Subtract the elements.
- Push the value into the stack using the function “push()”.
- Give function definition to multiply elements “mult()”.
- Declare required variables “number”, and “prod_Value”.
- Call the function “pop()”.
- Multiply the elements.
- Push the value into the stack using the function “push ()”.
- Give function definition to divide elements “div()”.
- Declare required variables “number”, and “quo_Value”.
- Call the function “pop()”.
- Divide the elements.
- Push the value into the stack using the function “push()”.
- Give function definition to add all the elements “addAll()”.
- Declare required variables “number”, and “sum_Value”.
- Call the function “pop()”.
- Add all the elements.
- Push the value into the stack using the function “push()”.
- Give function definition to multiply all the elements “multAll()”.
- Declare required variables “number”, and “prod_Value”.
- Call the function “pop()”.
- Multiply all the elements.
- Push the value into the stack using the function “push()”.
IntStack.h:
- Include required files.
- Declare a class named “IntStack”. Inside the class,
- Inside “protected” access specifier,
- Declare a pointer named “stackArray”.
- Declare variables “stackSize” and “top”.
- Inside “public” access specifier,
- Declare constructor and destructor.
- Give function declarations.
- Inside “protected” access specifier,
IntStack.cpp:
- Declare required header files.
- Give definition for constructor,
- Create a stack array and assign the size
- Give definition for destructor,
- Delete the array and assign it to null
- Give function definition to push elements “push()”
- Check if the stack is full using the function “isFull()”,
- If the condition is true then, print “The stack is full”.
- If the condition is not true then,
- Increment the variable.
- Assign “num” to the top position.
- Check if the stack is full using the function “isFull()”,
- Give function definition to pop elements “pop ()”,
- Check if the stack is empty using the function “isEmpty()”.
- If the condition is true then, print “The stack is empty”.
- Assign top element to the variable.
- Decrement the variable.
- If the condition is true then, print “The stack is empty”.
- Check if the stack is empty using the function “isEmpty()”.
- Give function definition to check if the stack is full “isFull()”.
- Assign “false” to the Boolean variable “status”.
- Check if the stack size if full.
- Assign true
- Return the Boolean variable “status”.
- Give function definition to check if the stack is empty “isEmpty()”.
- Assign “false” to the Boolean variable
- Check if top is empty
- Assign true.
- Return the variable
Main.cpp:
- Include required header files.
- Inside “main ()” function,
- Declare constant variables “STACKSIZE”, “ADDSIZE”, and “MULTSIZE”.
- Create three stacks “stack”, “addAllStack”, and “multAllStack”.
- Declare a variable “popVar”.
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
For C++
please just need cpp file
Data structure & Algorithum java program
1) Add a constructor to the class "AList" that creates a list from a given array of objects.2) Add a method "getPosition" to the "AList" class that returns the position of a given object in the list. The header of the method is as follows : public int getPosition(T anObject)3) Write a program that thoroughly tests all the methods in the class "AList".4) Include comments to all source code.
C programmingTopic: Stacks
Chapter 18 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - Prob. 5RQECh. 18 - The STL stack is considered a container adapter....
Ch. 18 - What types may the STL stack be based on? By...Ch. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - The STL stack container is an adapter for the...Ch. 18 - Prob. 18RQECh. 18 - Prob. 19RQECh. 18 - Prob. 20RQECh. 18 - Prob. 21RQECh. 18 - Prob. 22RQECh. 18 - Prob. 23RQECh. 18 - Prob. 24RQECh. 18 - Prob. 25RQECh. 18 - Prob. 26RQECh. 18 - Write two different code segments that may be used...Ch. 18 - Prob. 28RQECh. 18 - Prob. 29RQECh. 18 - Prob. 30RQECh. 18 - Prob. 31RQECh. 18 - Prob. 32RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Dynamic String Stack Design a class that stores...Ch. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Inventory Bin Stack Design an inventory class that...Ch. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
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
- Tic tac game in JAVAarrow_forwardData Structure & Algorithum java program Do the following: 1) Add a constructor to the class "LList" that creates a list from a given array of objects.2) Add a method "addAll" to the "LList" class that adds an array of items to the end of the list. The header of the method is as follows, where "T" is the generic type of the objects in the list. 3) Write a Test/Driver program that thoroughly tests all the methods in the class "LList".arrow_forwardExercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304arrow_forward
- The card that wins the trick def winning_card(cards, trump=None): Playing cards are again represented as tuples of (rank,suit) as in the cardproblems.py lecture example program. In trick taking games such as whist or bridge, four players each play one card from their hand to the trick, committing to their play in clockwise order starting from the player who plays 0irst into the trick. The winner of the trick is determined by the following rules: If one or more cards of the trump suit have been played to the trick, the trick is won by the highest ranking trump card, regardless of the other cards played. If no trump cards have been played to the trick, the trick is won by the highest card of the suit of the 0irst card played to the trick. Cards of any other suits, regardless of their rank, are powerless to win that trick. Ace is the highest card in each suit. Note that the order in which the cards are played to the trick greatly affects the outcome of that trick, since the 0irst…arrow_forwardFill in the blanksarrow_forwardCENGAGE MINDTAP Programming Exercise 9-2B O Instructions MeanMedian2.java + Revise the MeanMedian2 class from Chapter 9 Exercise 2A so that the user can enter any number of values up to 20. If the list has an even number of values, the median is the numeric average of the values in the two middle positions. Allow the user to enter 9999 to quit entering numbers. An example of the program is shown below: Enter number 8 or 9999 to quit 10 Enter number 9 or 9999 to quit 700 Enter number 10 or 9999 to quit 9999 size is 9 You entered: 25, 50, 500, 550, 450, 600, 200, The mean is 342.77777777777777 and the median is 450. The example above is abbreviated and included for guidance and does not include all the information generated by the program. Grading !!arrow_forward
- # Coding - Simulate a robot Write a program that simulates the movements of a robot. The robot can have three possible movements: turn right turn left advance The robot is placed on a hypothetical infinite grid, facing a particular direction (north, east, south, or west) at a set of `{x,y}` coordinates,e.g., `{3,8}`, with coordinates increasing to the north and east. Create a Class `Robot` that contains a method `execute` which given a number of instructions will calculate the robot's new position, and the the direction in which it is pointing. ## Example The letter-string "RAALAL" means: Turn right Advance twice Turn left Advance once Turn left yet again Say a robot starts at `{7, 3}` facing north. Running this stream of instructions should leave it at `{9, 4}` facing west. ## Inputs and Outputs The argument of the `execute` is `string` in the format `X Y BEARING COMMANDS`. The method should return a one-liner `string` in the format `X Y BEARING`. In the…arrow_forwardT or F -Functions are considered to be objects in JavaScript because they contain three critical attributes: data, methods that act on the data, parameters for passing the data also known as awareness. -A recursive function is a function that calls itself and eventually returns default value to break out of the recursion. -A function that is used to create a new object is called an anonymous function. -Attributes define additional characteristics or properties of the element which is the same as for the start tag. -Javascript is similar to the Java programming languagearrow_forwardComputer engineering question Assignment 3:- Apex (Salesforce)- Create an apex class - In the apex class we have to create 1 method.- Method return type is void & the argument is null.- Method : - Map<String,String> static 4 values---- Put the value at the time of initialization---- Put the value using the map method PUTarrow_forward
- Modular Programming: Your program should be modular and consists of the following functions: a) read(): - Ask the user for a valid atomic number (Z) b) compute_binding_energy(Z, table): - Build the table (a list of lists) of binding energy where the columns are: the mass number (A), the binding energy (Eb) and the binding energy per nucleon (BEN), while the rows range from A = Z to A = 4Z c) most_stable(table) : - Find and return the row that contains the highest binding energy per nucleon, which corresponds to the most stable configuration. d) print_table(table): - Print the table in a neat tabular format as shown in the sample run in figure 2. e) write_to_file(table, file_name): - Save the table in a text file output.txt as shown in figure 3. 4 f) main(): - The main function is set up to make the calls to the functions as specified in points a) to e)arrow_forwardCodeWorkout Gym Course Q Search kola shreya@ columbusstate.edu Search exercises... X274: Recursion Programming Exercise: Cannonballs X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine. cannonballs, and so forth. Given the following recursive function signature, write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains. Examples: cannonball(2) -> 5 Your Answwer: 1 public int cannonball(int height) { 3. 4} Check my answer! Reset Next exercise Feedbackarrow_forwardxcvcxarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage