Computer Science 3675
Fall 2000
Programming Assignment 8

Due: Nov 30

Procedural and functional programming both encourage you to organize programs so that similar functions working on different kinds of data are grouped together. For example, when you write the derivative function, all of the different kinds of derivative formulas are put into a single function that computes all different kinds of derivatives. A single simplification function has to deal with any kind of expression, and all simplifications are grouped together.

Object-oriented programming encourages you to organize your program so that different operations that work on the same kind of data are grouped together. For example, all functions (such as computing the derivative and simplification) that work on expressions that are sums are put in one place, and those that work on products are put someplace else. This organization tends to result in software that is more flexible and easier to work with.

The organization method that object-oriented programming encourages makes some special requirements on a programming language. It must be able to perform some run-time type checking, so that it can check what kind of thing a function is acting on. The language implementation must also be able to find appropriate functions, even though they are spread among different modules.

The assignment

For this assignment, rework your derivative program into a more object-oriented form. You will not go all the way to object-oriented programming here, but only part of the way. Build a separate file for each kind of expression. All of the operations on a given kind of expression should be put together.

Get files Expression.ast, XExpr.ast, ConstantExpr.ast and SumExpr.ast, implementing the concepts of an expression (a general expression), a variable, a constant and a sum, respectively. Look at them as examples of how to write your new files. Also get TestExpr.ast, which contains some tests of these.

  • Expression.ast
  • ConstantExpr.ast
  • XExpr.ast
  • SumExpr.ast
  • TestExpr.ast
  • Add new files to cover difference, products and constant powers, as in the previous assignment. Use one file for each new concept.

    You should not have to modify files XExpr.ast, ConstantExpr.ast, SumExpr.ast or Expression.ast at all in order to write your new files. Just add new files. The tester will need to be modified, to make it do more tests. Do not turn in untested programs.

    Turning in your assignment

    Use the handin program with program number 8. Submit only the new files that you have added, not the ones that you got. Also submit your modified tester. Be sure that it does a reasonable test suite. It should, at the very minimum, execute every line that you wrote.