//-------------------------------------------------------------------- // // Laboratory 11 test11.C // // Test program for the operations in the Expression Tree ADT // //-------------------------------------------------------------------- #include #include "exprtree.h" //-------------------------------------------------------------------- // // Function prototype void dummy ( ExprTree copyTree ); // copyTree is passed by value //-------------------------------------------------------------------- void main() { ExprTree testExpression; // Test expression cout << endl << "Enter an expression in prefix form : "; testExpression.build(); testExpression.showStructure(); testExpression.expression(); cout << " = " << testExpression.evaluate() << endl; //2 // Test the copy constructor. (In-lab Exercise 2) //2 dummy(testExpression); //2 cout << endl << "Original tree:" << endl; //2 testExpression.showStructure(); //3 // Test the commute operation. (In-lab Exercise 3) //3 testExpression.commute(); //3 cout << endl << "Fully commuted tree: " << endl; //3 testExpression.showStructure(); //3 testExpression.expression(); //3 cout << " = " << testExpression.evaluate() << endl; cout << endl << "Clear the tree" << endl; testExpression.clear(); testExpression.showStructure(); } //-------------------------------------------------------------------- void dummy ( ExprTree copyTree ) // 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(); }