Question
using c++ i nedd the implemntation of each function please // // ExpressionTree.h // // Class declarations for the linked implementation of the // Expression
using c++ i nedd the implemntation of each function please // // ExpressionTree.h // // Class declarations for the linked implementation of the // Expression Tree ADT -- including the recursive helpers for the // public member functions // // Instructor copy with the recursive helper function declarations. // The student version does not have those, but has a place to write // the declarations in the private section. // //--------------------------------------------------------------------
#ifndef EXPRESSIONTREE_H #define EXPRESSIONTREE_H
#include
using namespace std;
template
// Constructor ExprTree (); ExprTree(const ExprTree& source);
ExprTree& operator=(const ExprTree& source);
// Destructor ~ExprTree ();
// Expression tree manipulation operations void build (); void expression () const; DataType evaluate() const throw (logic_error); void clear (); // Clear tree void commute(); bool isEquivalent(const ExprTree& source) const;
// Output the tree structure -- used in testing/debugging void showStructure () const;
private:
class ExprTreeNode { public: // Constructor ExprTreeNode ( char elem, ExprTreeNode *leftPtr, ExprTreeNode *rightPtr );
// Data members char dataItem; // Expression tree data item ExprTreeNode *left, // Pointer to the left child *right; // Pointer to the right child };
// Recursive helper functions for the public member functions -- insert // prototypes of these functions here.
// Data member ExprTreeNode *root; // Pointer to the root node };
#endif // #ifndef EXPRESSIONTREE_H
//-------------------------------------------------------------------- // // Laboratory 8 test8.cpp // // Test program for the operations in the Expression Tree ADT // //-------------------------------------------------------------------- #include "stdafx.h" #include
using namespace std;
//#include "ExprTree.cpp" #include "ExpressionTree.cpp" #include "config.h"
//-------------------------------------------------------------------- // Function prototype
template
//--------------------------------------------------------------------
int main() { #if !LAB8_TEST1 || LAB8_TEST2 || LAB8_TEST3 // Don't do this if testing boolean tree, unless also testing programming // exercises 2 or 3 (for which this section is mostly needed). // The tricky part occurs if testing exercise 1 and (2 or 3), or if // someone is trying to test the basic class and one of the other exercises // in parallel. Hence the #if expression above. cout << "Start of testing the basic expression tree" << endl; ExprTree
cout << endl << "Enter an expression in prefix form : ";
testExpression.build(); testExpression.showStructure(); testExpression.expression(); cout << " = " << testExpression.evaluate() << endl;
// Test the copy constructor. dummy(testExpression); cout << endl << "Original tree:" << endl; testExpression.showStructure(); #endif
#if LAB8_TEST1 cout << "Start of testing the boolean expression tree" << endl; ExprTree
#if LAB8_TEST2 cout << "Start of testing commute()" << endl; testExpression.commute(); cout << endl << "Fully commuted tree: " << endl; testExpression.showStructure(); testExpression.expression(); cout << " = " << testExpression.evaluate() << endl; cout << "End of testing commute()" << endl; #endif
#if LAB8_TEST3 cout << "Start of testing isEquivalent()" << endl; ExprTree
ExprTree
ExprTree
#if !LAB8_TEST1 && !LAB8_TEST2 && !LAB8_TEST3 // Don't bother with this if testing any of the programming exercises cout << endl << "Clear the tree" << endl; testExpression.clear(); testExpression.showStructure(); cout << "** End of testing the basic expression tree" << endl; #endif
return 0; }
//--------------------------------------------------------------------
template
// Dummy routine that is passed an expression tree using call by // value. Outputs copyTree and clears it.
{ cout << endl << "Copy of tree: " << endl; copyTree.showStructure(); copyTree.clear(); cout << "Copy cleared: " << endl; copyTree.showStructure(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started