CS141:    Assignment 1

Version 1.0   Be sure to check the mailing list for updates and corrections and hints.

Due dat has been postponed to Jan 31 Thu

Same times: noon for electronic copies, begining of class
for hardcopies.

Due on:
Tuesday 29th Jan
Written part: at the beginning of each class
by 3:40 or 5:10 for each section the written part of the assignment should be on MY DESK.
After this time with MY WATCH, I may consider assignments late.
You can give the assignment to a TA before that time.
The programming part will have to be submitted electronically by noon on the same day Tu 29 Jan.

Note: You have to write your full name with capitalized last name, your last four digits,
AND your class section AND your lab section.
Failure to do so
or if the writing is incomprehensible will result in substantial reductions.
Read policies and rules.
Also, if you want to see your grades published you should
print, sign and give to your TAs the printout from the syllabus page.

Written Part.  [30]

Returned both as hard copy and with the electronic part.
Use simple text files, pdf or postscript. You have to write a 1-3 to page report and a few pages of
output. You need to explain what your program is doing and how it is
doing it. The idea is that the grader should be able to read this
and understand how well your program works. Therefore you should have:
  • a brief paragraph per class, especially the ones whose implementation can be done in various ways.
  • Explain why you choose a particular implementation or algorithm when this is not trivial.
  • Report problems that your program has
  • Report extra futures that you added in your program
  • Report limitations (ie my program does not check for wrong input)
  • Explain what is the complexity of your algorithm of
    evaluating an expression as a function of
  • Outputs of your program to the given test cases, plus
    2-3 more if you think that they can help evaluate your program.
    Try to group your output in a condensed format. Printing
    one number in a page is not good use of paper. Overly long or overly short reports will loose marks.

    WARNING: A report that makes false claims about the program will be
    considered as cheating. An output sample which you give that can not
    generated by the submitted program will also be considered as
    cheating. Your program will be run, and inspected for style, and
    coding plagiarism. There are automatic tools that do that with very
    high accuracy. In general, don't even think about it.

    Programming part.  [70]

    Note: you are not allowed to use STL or any other advanced libraries.
    The programs have to compile in Linux on hill.cs. Don't leave this to
    the last moment. Make sure you can compile a preliminary version.
    You will implement a kind of tree that helps us evaluate numerical
    expressions of positive numbers. We have three operations: MIN, MAX,
    and average AVG of two values. Every node of the tree is a:
  • an operation
  • a number
    INPUT. The input is in this order: we first have the operator and then two
    expressions that the operator is applied on. An expression is a) a
    number or b) another operation. For your convenience, each operator
    applies to two only expressions

    The input consists of positive numbers and the
    following negative numbers to imply: MIN (= -1), MAX (= -2), and AVG (= -3).
    White spaces, tabs and newlines are ignored.
    Your program should not crash for weird input i.e. only one child.
    However on erroneous input you can just exit.
    Example: MIN 5 4 should create a tree that has as root a node
    a node that corresponds to MIN and two children that correspond
    to left child 5 and right child 4.
    Similarly: MIN MAX 4 8 6 corresponds to a tree:
    Level 0: root: MIN
    Level 1: children of root: MAX and 6
    Level 2: children of MAX: 4 and 8
    The required output (see below) is the following: output.
    Note that the first child in the input file is the left one. Also in the
    print out, you should use the words MIN, MAX, AVG and not negative numbers.
    Finally, you should first print the children of a node and then
    move to its sibling.
    EXECUTION. The program should compile to an executable named:
    "evalTree". The program should take as a parameter a file:
    > evalTree file-name
    Failure to run this way will result in mark reduction.
    We need uniformity to facilitate testing.

    You will be given the start of the code and some definitions combined definitions files, but we already covered these in the class.
    The test cases are (in progress): 1) test1, 2) test2 invalid input, 3) test3, 4) test4 invalid input, 5) test5 large input.
    However, your program may be tested on other cases too.
    You have to write the methods and add more fields as necessary.
    You have to use the existing definitions, assume you that you
    are hired to extend an ongoing project.
    You are required to provide the following functionality.

  • Read from a file in the format show above. Numbers can be real.
  • Create a tree data structure of the Class node (given in the template) that actually implements the corresponding tree.
  • Print out the tree using 10-spaces every time you move down a layer.
    For clarity you should start the line with the depth of the tree
    at that point. As in the example above.
  • Evaluate the tree printing all intermediate results in the order they
    executed in your program:
    MAX 4 and 8 = 8
    MIN 8 and 6 = 6
    Final result = 6
  • Calculate the depth of the tree. Depth is the maximum distance of a leaf
    from the "root". Example, MAX 4 8 has depth of one. Example, MAX 4 MIN 2 3
    has depth of two.
    Check:  http://www.cs.ucr.edu/~klick/    the links for linux (for makefiles) and programming for
    stylistic and programming suggestions.