Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Please need your help. Link to the code, I'm working on is in the comments You must use an ArrayStack to complete this exercise.

Hello, Please need your help.

Link to the code, I'm working on is in the comments

image text in transcribedimage text in transcribed
You must use an ArrayStack to complete this exercise. Your name should be added to the Javadoc comment block at the top of the client. Example run: Enter an arithmetic expression on a single line ('q' to end): 5+5 5+8 - 13 Enter an arithmetic expression on a single line ('q' to end): 2+l6 2+16 = 3 Enter an arithmetic expression on a single line ('q' to end): See/2 5-9/2 ' 3 Enter an arithmetic expression on a single line ('q' to end): ;#9'27 1+9*24 = 15 Enter an arithmetic expression on a single line ('q' to end): 2-1-5'2/2 2-1+5*2/2 = 6 Enter an arithmetic expression on a single line ('q' to end): q You will demonstrate your understanding of stacks in this exercise. Only 1 program is to be completed. All les require Javadoc documentation comments at the top to include a description of the program, the @le tag, and an @author tag with your name. Class specication les include complete Javadoc documentation comments for all public members. Write a function that uses an ArrayStack to evaluate a simple arithmetic expression given in string format. The function is to be implemented within the given client. The ym 3, code is complete; add Javadoc documentation to either the StackADT.h or the ArrayStack.h that describes the code written there. The ArrayStack is a template. Therefore, ArrayStack.cpp is not in the project directory but is in the Files directory and can be accessed from there. The les directory also contains main.cpp which was used to test the functions in ArrayStack class, if you want to take a look at it. The main() function for this project is in Arithmeticcpp; it queries the end user for a string arithmetic expression. The main() function calls the eval() function to evaluate and return the result of the arithmetic expression passed as a parameter. Lastly, the main() function displays the result to the end user. Any number of expressions may be evaluated. The main() function is completed. You are responsible for the implementation of the eval() function. The eval() function parameter will be a string consisting of a properly formed arithmetic expression using only the values 0 through 9 and + (addition), - (subtraction), * (multiplication), / (division), and/or " (exponentiation) operators. The expression will not include decimals, negative values, or values above 9. The expression will not include parenthesis but may include spaces, which should be skipped. The eval() function needs to use two ArrayStacks: one to store the numeric values and the other to store the operators. When a number is encountered in the string, push it on the values stack. When an operator is encountered in the string, push it on the operators stack if it has a higher operator precedence than the operator currently on the top of the stack. Otherwise, pop an operator off the operator stack, pop two numbers off the values stack, and push the result of the computation onto the values stack. This should be repeated until the operator at the top of the operators stack has a lower precedence than the current operator. Once this point is reached, push the current operator on the operators stack. Once the end of the arithmetic expression is reached, clear the stacks by popping off an operator from the operators stack, popping two numbers off the values stack, perform the computation and push the result onto the values stack. Continue until the operators stack is empty. The nal result will be the remaining value on the values stack. Pop off this value and return it as the result of the eval() function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What constitutes an agreement?

Answered: 1 week ago