akosiraff

Download Expression Trees

Aug 25th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/programming-project-expression-trees/
  3. Programming Project: Expression Trees
  4. This project is adapted from Project 1 of Chapter 9 of the textbook. It deals with a simple kind of
  5. expression trees, in which there are two kinds of nodes:
  6. (a) Leaf nodes, which contain a real number as their clement; and
  7. (b) Non-leaf nodes, which have exactly two children and contain one of these characters as their
  8. element: +, -, * and /. These characters represent arithmetic operations and have usual
  9. interpretations.
  10. Implement a class for expression trees with these operations:
  11. (a) A constructor that builds an expression tree. It accepts a String that represents a grammatically
  12. correct expression as its sole input. Hint: refer to a previous assignment on evaluating
  13. expressions.
  14. (b) A recursive method named eval that evaluates a non-empty expression tree using these rules:
  15. i. If the tree has only one node (which must be a leaf), then eval returns the real number
  16. that is the node’s clement;
  17. ii. If the tree has more than one node and the root contains op where op is one of +, -, * and
  18. /, then eval first evaluates the sub-trees of the root and returns the real number obtained
  19. by performing operation op on the results from evaluating the sub-trees.
  20. (c) A recursive method named infix that output the expression represented by a non-empty
  21. expression tree to a String in infix format.
  22. (d) A recursive method named postfix that outputs the expression represented by a non-empty
  23. expression tree in postfix format.
  24. You also need to write another class that applies the operations of the above class.
  25. Please submit
  26. 1. Analysis: test data;
  27. 2. Design:
  28. ? A class invariant for each class;
  29. ? Pre/Post conditions for required operations;
  30. ? Algorithms for required operations.
  31. 3. Code;
  32. 4. Screen snapshots of test runs.
  33. Download: http://solutionzip.com/downloads/programming-project-expression-trees/
Add Comment
Please, Sign In to add comment