The main() function for this project is in Arithmetic.cpp; 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 final result will be the remaining value on the values stack. Pop off this value and return it as the result of the eval() function. ARTHEMTIC.CPP #include #include #include "ArrayStack.h" float eval(std::string); // The following main function should not be modified int main(void) { std::string expression = "Continue"; do { std::cout << "Enter an arithmetic expression on a single line ('q' to end): "; getline(std::cin, expression); if (expression[0] != 'q') { float result = eval(expression); std::cout << expression << " = " << result << std::endl; } } while (expression[0] != 'q'); return 0; } float eval(std::string expr) { // To be implemented // Any number of support functions may also be added std::cout << "eval function not implemented" << std::endl; return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help me complete this project. I am very confused and lost.

The main() function for this project is in Arithmetic.cpp; 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 final result will be the remaining value on the values stack.  Pop off this value and return it as the result of the eval() function.

ARTHEMTIC.CPP

#include <cstdlib>
#include <iostream>
#include "ArrayStack.h"

float eval(std::string);

// The following main function should not be modified
int main(void) {
std::string expression = "Continue";

do {
std::cout << "Enter an arithmetic expression on a single line ('q' to end): ";
getline(std::cin, expression);
if (expression[0] != 'q') {
float result = eval(expression);
std::cout << expression << " = " << result << std::endl;
}
} while (expression[0] != 'q');

return 0;
}

float eval(std::string expr)
{ // To be implemented
// Any number of support functions may also be added
std::cout << "eval function not implemented" << std::endl;
return 0;
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 9 steps with 12 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY