CPSC 241-002 Computer Science IV
(Data Structures and Algorithms)

Fall 1998
TTh 12:30--1:45 Daniel 408
Assignment 7
<http://andrewd.ces.clemson.edu/courses/cpsc241/fall98/hw/asg7.html>

Objectives:
To apply previously learned data structures.

Due date:
10/29/98 (** extended due to system down time **)

Teams:
You may organize yourselves into small teams (of size no larger than 4) to complete this assignment.

If you form a team, you must specify the ``division of labor'' (e.g., who did what) in your assignment writeup (scores will be divided equally, however).

Teams organization deadline:
10/20/98

You must notify me of the team you have formed by this date (email is fine, or you may submit a hardcopy naming your team members). If you have not formed a team, you can elect to remain solo, or request to be included in a team, and I will arbitrarily form teams from remaining solo students.

Description:
  1. Following the simple (binary operator) calculator description of section 11.2, implement an infix calculator.

  2. Unlike the text's solution, however, use both a stack and binary tree to implement the calculator. The stack is used, in a manner similar to the book, to help parse the input string. The tree is to be used to store the input expression (the tree is thus to be used as an ``expression tree'').

  3. For your output, print out the expression in postfix notation, then print out the calculated answer.

  4. In your assignment writeup, clearly specify the limitations or features of your program. For example, does it handle parentheses (nested expressions), unary operators, etc.

    Suggestions:
    1. Follow the book's general solution design up to the actual processing of the ``tokens'' (e.g., routines to parse and process the input string).
    2. Use an Evaluator class to handle the actual input string evaluation.
    3. Use a stack to push and pop symbol ``tokens'' as they are encountered.
    4. Use a routine similar to the book's ProcessToken, except that instead of performing the binary operation (via the BinaryOp routine), as the token is being processed, insert it onto the binary expression tree. Take care to properly insert the token so that a postorder traversal of the tree generates the correct postfix expression---this is the trickiest part of the program).
    5. Evaluate the expression by traversing the expression tree in postfix order (e.g., in reverse-Polish notation).

    What to hand in:
    ``Professional-quality'' writeup (one writeup per team), including:
    1. Cover page containing names of all participants:
      Course Id--Section No.
      Name:
      SS No:
      Assignment No.
    2. Assignment description
    3. Solution description (e.g., program design, description of algorithm, etc., however appropriate).
    4. Lessons learned, identified interesting features of your program
    5. Appendix A: Source code listing
    6. Appendix B: Sample input (if any)
    7. Appendix C: Sample output
    The entire document should be a clearly written account of what you were to accomplish, what you in fact did accomplish, and what you learned (how you accomplished it). The code and sample runs, listed in the appendices, should be clearly documented (e.g., document the source code, generate informative output).

    The general presentation of your document counts! (This includes qualities such as neatness, formatting, and legibility.)