Question: The expressionConverter cpp file needs to be filled out only // expressionConverter.h #pragma once #include #include using namespace std; class ArithNode { public: bool isOperator;

 The expressionConverter cpp file needs to be filled out only //

The expressionConverter cpp file needs to be filled out only

// expressionConverter.h

#pragma once #include #include

using namespace std;

class ArithNode { public: bool isOperator; char binaryOperator; // set only if isOperator = true int operand; // set only if isOperator = false ArithNode *left; ArithNode *right;

ArithNode(char op) { left = NULL; right = NULL; binaryOperator = op; isOperator = true; }

ArithNode(int n) { left = NULL; right = NULL; operand = n; isOperator = false; }

};

string Infix2RPN(string); string RPN2Infix(string); ArithNode *Infix2ExpressionTree(string); ArithNode *RPN2ExpressionTree(string); int EvaluateInfix(string); int EvaluateRPN(string); =================================================================================== // expressionConverter.cpp

#include "ExpressionConverter.h"

// This part needs to be filled out

==================================================================================== // main.cpp

#include #include #include #include

#include "ExpressionConverter.h"

////////////////////////////////////////////////////////////////////////////////////////////// // DO NOT EDIT THIS FILE (except for your own testing) // CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS //////////////////////////////////////////////////////////////////////////////////////////////

using namespace std;

template bool testAnswer(const string &nameOfTest, const T &received, const T &expected); bool testString(const string &nameOfTest, const string &received, const string &expected); bool testTree(const string &nameOfTest, const ArithNode *ptr, const string &expected); void printTree(ArithNode *ptr); bool passedAllTests = true;

int main() {

// Convert and evaluate infix expression { string infix = "10 * ( 20 + 30 )"; cout

if (passedAllTests) cout

template bool testAnswer(const string &nameOfTest, const T &received, const T &expected) { if (received == expected) { cout

string removeWhitespace(const string &s) { string t; for (int i = 0; i

bool testString(const string &nameOfTest, const string &received, const string &expected) { if (removeWhitespace(received) == removeWhitespace(expected)) { cout

string tree2string(const ArithNode *ptr) { if (ptr == nullptr) return ""; string s; if (ptr->isOperator) s = string(1, ptr->binaryOperator) + "(" + tree2string(ptr->left) + ")" + "(" + tree2string(ptr->right) + ")"; else s = to_string(ptr->operand); return s; }

bool testTree(const string &nameOfTest, const ArithNode *ptr, const string &expected) { string received = tree2string(ptr); if (received == expected) { cout

void printTree(ArithNode *ptr, string prefix, bool isTail) { if (!ptr->isOperator) { cout " : "> ") operand " : "> ") binaryOperator left, prefix + (isTail ? " " : "=> "), false); printTree(ptr->right, prefix + (isTail ? " " : "=> "), true); }

void printTree(ArithNode *ptr) { printTree(ptr, "", true); } ========================================================================================================================

Objective You are to write a C++program that will ask the user to enter an arithmetic expression in either infix or RPN. Your program should then return the expression in other notations (infix, RPN, and expression described above. You are given the declarations of functions which will be called from main to convert and evaluate expression tree. tested in the provided main.cpp expressions. Your are also given a class ArithNode which is to be used for nodes of a binary You are to write the definitions of only the functions, adding other functions as needed. Your code is Objective You are to write a C++program that will ask the user to enter an arithmetic expression in either infix or RPN. Your program should then return the expression in other notations (infix, RPN, and expression described above. You are given the declarations of functions which will be called from main to convert and evaluate expression tree. tested in the provided main.cpp expressions. Your are also given a class ArithNode which is to be used for nodes of a binary You are to write the definitions of only the functions, adding other functions as needed. Your code is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!