so there is 3 different folder. arithmeticExpression.h / main.cpp / arithmeticExpression.cpp
In this lab you will complete a program that builds and traverses an Arithmetic Expression Tree, then outputs the resulting tree using the drawing software Graphviz (short for Graph Visualization Software). ArithmeticExpression class #ifndef ARITHMETICEX PRESSION H #define ARITHMETICEXPRESSION H include
#include using namespace std; struct TreeNode char data; char key; TreeNode lefti TreeNode* right; TreeNode (char data, char key) :data (data),key (key),left (0),right (0) class arithmeticExpression( private string infixExpression; TreeNode root; public: /Initializes an empty tree and sets the infixExpression to the value of parameter passed in arithmeticExpression (const string&) Implementation of destrucor is optional The destructor should deallocate all the nodes in the tree./ //arithmeticExpression) /Converts the infixExpression to its equivalent postfix string and then generates the tree and assigns the root node to the root data field. The key for the first node is 'a', 'b' for the second node and void buildTree / Calls the recursive infix function. * so on. void infix) Calls the recursive prefix function. */ void prefix) Calls the recursive postfix function. void postfix) *Calls the recursive visualizeTree function and generates the .png file using void visualizeTree (const string&); system call. * private: Helper function that returns an integer according to the priority of the given operator. int priority (char); Helper function that returns the postfix notation equivalent to the given infix expression * string infix_to_postfix ) Helper function that outputs the infix notation of the arithmetic expression tree by performing the inorder traversal of the tree An opening and closing parenthesis must be added at the beqinninq and endinq of each expression. An opening and closing parenthesis must be added at the beginning and ending of each expression. void infix(TreelOd *); Helper function that outputs the prefix notation of the arithmetic expression tree by performing the preorder traversal of the tree. * void prefix (TreeNode / Helper unction that outputs the postfix notation of the arithmetic expression by performing the postorder traversal of the tree. * void postfix(TreeNad ); *Helper Function for generating the dotty file. This is a recursive function. */ #endif Here is the implementation of the functions priority, infix_to_postfixand visualizeTree. You should implement the rest of functions. int arithmeticExpressian ::priority 4 char int priority -C op] priority-3 priority-2i else if(op = '+' 11 op == '-') priority-1 return priority string arithmeticExpression: infix_to_postfix( stack s; ostringstream. ossi char c for(unsigned 1-0; i include "arithmeticExpression.h" using namespace std,; int maino string exprl-"atb arithmeticExpression exl (exprl) ex1.buildTree) cout key16, key8 > keyl,; key8 > key11; key15 -> key13 keyl6-> key25; Line 1 gives the graph name (G1) and type (digraph). The lines that follow creates nodes, edges, or subgraphs and set attributes. You may use Quotes to protect punctuation and white spaces. A node is created when its name first appears in the file (e.g. key12). An edge is created when nodes are joined by the edge operator->.To visualize the above graph, copy and paste the above code into a new file and save it as 'simple_bst.dot file and then run the following command dot -Tpng simple_bst.dot -o graph.jpg Once you execute the above command into a terminal, a visualization of the graph is going to be created into an image called graph.jpg. 2. height_color.dot: The following code contains the representation for a tree (called G2) with nodes' labels that indicate the node's key and the node's height in the tree digraph G2 nodes a [color- lightblue, stylefilled, Label-"key-4, h-2" b [color-1ightblue, style-filled, Label-"key-2, h-1" c [color= lightblue, style filled, label-"key-6, h=1"]; d [color- lightblue, stylefilled, Label-"key-, h-0" e [color-1ightblue, style-filled, label-"key-3, h-0" f [color= lightblue, style = filled, label-"key=5, h=0"]; g [color- lightblue, style filled, Label-"key-7, h-0" // edges a-> c; b -> d: b-e c-> f; c-> g; 3. inorder color.dot: The following code is the representation for G3 tree with nodes' labels that indicate the node's kew and the node's order in which it is visited in an inorder traversal of the tree. digraph G3 i nodes a [color= red, peripheries-2, style filled, Label-key-4, in-4"]; b [color - red, peripheries-2, style-filled, Label-"key-2, in-2"1 c color- red, peripheries-2, stylefilled, label-"key-6, in-5" d [colorred, peripheries-2, style filled, label-"key-, in-1" e Icolor - red, peripheries-2, style-filled, label-"key-3, in-3" f color-red, peripheries-2, style-filled, label-"key-5, in-5" g [color= red, peripheries-2, style = filled, Label-key=7, in-7"]; digraph G3 // nodes a [color- red, peripheries-2, style-filled, label-"key-4, in-4" b [color-red, peripheries-2, style-filled, label-"key-2, in-2"] c [color- red, peripheries-2, style-filled, label-"key-6, in-6" d [color- red, peripheries-2, style-filled, label-"key-1, in-l" e [color- red, peripheries-2, style-filled, label-"key-3, in-3" f color-red, peripheries-2, style filled, label-"key-5, in-5", g [color- red, peripheries-2, style-filled, label-"key-7, in-7" // edges ab a-> c; b->d; c-> f; c-> g; In this lab you will complete a program that builds and traverses an Arithmetic Expression Tree, then outputs the resulting tree using the drawing software Graphviz (short for Graph Visualization Software). ArithmeticExpression class #ifndef ARITHMETICEX PRESSION H #define ARITHMETICEXPRESSION H include #include using namespace std; struct TreeNode char data; char key; TreeNode lefti TreeNode* right; TreeNode (char data, char key) :data (data),key (key),left (0),right (0) class arithmeticExpression( private string infixExpression; TreeNode root; public: /Initializes an empty tree and sets the infixExpression to the value of parameter passed in arithmeticExpression (const string&) Implementation of destrucor is optional The destructor should deallocate all the nodes in the tree./ //arithmeticExpression) /Converts the infixExpression to its equivalent postfix string and then generates the tree and assigns the root node to the root data field. The key for the first node is 'a', 'b' for the second node and void buildTree / Calls the recursive infix function. * so on. void infix) Calls the recursive prefix function. */ void prefix) Calls the recursive postfix function. void postfix) *Calls the recursive visualizeTree function and generates the .png file using void visualizeTree (const string&); system call. * private: Helper function that returns an integer according to the priority of the given operator. int priority (char); Helper function that returns the postfix notation equivalent to the given infix expression * string infix_to_postfix ) Helper function that outputs the infix notation of the arithmetic expression tree by performing the inorder traversal of the tree An opening and closing parenthesis must be added at the beqinninq and endinq of each expression. An opening and closing parenthesis must be added at the beginning and ending of each expression. void infix(TreelOd *); Helper function that outputs the prefix notation of the arithmetic expression tree by performing the preorder traversal of the tree. * void prefix (TreeNode / Helper unction that outputs the postfix notation of the arithmetic expression by performing the postorder traversal of the tree. * void postfix(TreeNad ); *Helper Function for generating the dotty file. This is a recursive function. */ #endif Here is the implementation of the functions priority, infix_to_postfixand visualizeTree. You should implement the rest of functions. int arithmeticExpressian ::priority 4 char int priority -C op] priority-3 priority-2i else if(op = '+' 11 op == '-') priority-1 return priority string arithmeticExpression: infix_to_postfix( stack s; ostringstream. ossi char c for(unsigned 1-0; i include "arithmeticExpression.h" using namespace std,; int maino string exprl-"atb arithmeticExpression exl (exprl) ex1.buildTree) cout key16, key8 > keyl,; key8 > key11; key15 -> key13 keyl6-> key25; Line 1 gives the graph name (G1) and type (digraph). The lines that follow creates nodes, edges, or subgraphs and set attributes. You may use Quotes to protect punctuation and white spaces. A node is created when its name first appears in the file (e.g. key12). An edge is created when nodes are joined by the edge operator->.To visualize the above graph, copy and paste the above code into a new file and save it as 'simple_bst.dot file and then run the following command dot -Tpng simple_bst.dot -o graph.jpg Once you execute the above command into a terminal, a visualization of the graph is going to be created into an image called graph.jpg. 2. height_color.dot: The following code contains the representation for a tree (called G2) with nodes' labels that indicate the node's key and the node's height in the tree digraph G2 nodes a [color- lightblue, stylefilled, Label-"key-4, h-2" b [color-1ightblue, style-filled, Label-"key-2, h-1" c [color= lightblue, style filled, label-"key-6, h=1"]; d [color- lightblue, stylefilled, Label-"key-, h-0" e [color-1ightblue, style-filled, label-"key-3, h-0" f [color= lightblue, style = filled, label-"key=5, h=0"]; g [color- lightblue, style filled, Label-"key-7, h-0" // edges a-> c; b -> d: b-e c-> f; c-> g; 3. inorder color.dot: The following code is the representation for G3 tree with nodes' labels that indicate the node's kew and the node's order in which it is visited in an inorder traversal of the tree. digraph G3 i nodes a [color= red, peripheries-2, style filled, Label-key-4, in-4"]; b [color - red, peripheries-2, style-filled, Label-"key-2, in-2"1 c color- red, peripheries-2, stylefilled, label-"key-6, in-5" d [colorred, peripheries-2, style filled, label-"key-, in-1" e Icolor - red, peripheries-2, style-filled, label-"key-3, in-3" f color-red, peripheries-2, style-filled, label-"key-5, in-5" g [color= red, peripheries-2, style = filled, Label-key=7, in-7"]; digraph G3 // nodes a [color- red, peripheries-2, style-filled, label-"key-4, in-4" b [color-red, peripheries-2, style-filled, label-"key-2, in-2"] c [color- red, peripheries-2, style-filled, label-"key-6, in-6" d [color- red, peripheries-2, style-filled, label-"key-1, in-l" e [color- red, peripheries-2, style-filled, label-"key-3, in-3" f color-red, peripheries-2, style filled, label-"key-5, in-5", g [color- red, peripheries-2, style-filled, label-"key-7, in-7" // edges ab a-> c; b->d; c-> f; c-> g