CS 102 Lecture Notes

Week Six, Thursday: Pointers and Dynamic Arrays (continued)

Polynomial Class

A one-variable polynomial is an arithmetic expression of the form:

akxk + ... + a2x2 + a1x1 + a0x0

The highest exponent, k, is called the degree of the polynomial, and the real number constants a0, a1, ... are the coefficients of the polynomial. A class to represent polynomials can be created by using a dynamic array to hold the coefficients.

Operations on polynomials supported by the class could include:

ADT Comparison

The Bag ADT, String ADT, Geometry classes, and Bonsai example: what do these have in common and how do they differ? Examine the design decisions in light of their specifications: how they are designed is determined by what they are intended to do.

The String and Bag classes are intended to be general, frequently used, utility classes. They must have a variety of general purpose public member functions and overloaded operators.

The Geometry3D library is intended to be a special purpose tool kit for construction of virtual 3D spaces. Geometric objects are composed by making copies of the objects passed to their constructors. The library must also have a full complement of general purpose member functions and overloaded operators.

The Bonsai example illustrates a custom object model created for a special purpose. Bonsai classes are used for keeping track of real-world configurations (an object database). It can answer questions like "which tree is in which pot?" and "What trees are part of this bonsai?" A bonsai object is constructed by keeping pointers to existing tree and pot objects, not by making copies of them.


This page established September 26, 1999; last updated February 14, 1999.