Computing & Information Systems

Trent University

Assignment 1

Polynomials

Due Thursday, October 11, 2018 at 11:59pm.

A late penalty of 10% per day is assessed until Tuesday, October 16, 2018 at 11:59pm.

No assignment will be accepted after Tuesday, October 16, 2018 at 11:59pm.

Introduction

A univariate polynomial is defined as the sum of terms of the form axb where a is a real coefficient, x is a variable, and b ≥ 0 is an integer exponent. Therefore, the following mathematical expressions are univariate polynomials.

4.5×3 – 2.1×2 + 6.2x – 9.7

-8.3×4 + 7.6x

2.0×2

0

The degree of a polynomial is defined as its highest-valued exponent. Hence, the degrees of the four polynomials above are 3, 4, 2 and 0, respectively. Note as well that the terms of each polynomial are sorted by decreasing exponent values.

The following mathematical expressions are not univariate polynomials (do you know why?).

x2 + x – x -2

9.4xy

In this assignment, each pair of programmers is expected to create, manipulate, and output a collection of polynomials via a menu-driven user interface.

Learning Objectives

1) To become familiar with the manipulation of linked lists.

2) To use the library class List.

3) To implement interfaces.

Task 1: Class Term (10 marks)

The class Term encapsulates the coefficient and exponent of a single term. Exponents are limited to in range from 0 to 255.

public class Term : IComparable

{

private double Coefficient;

private byte Exponent;

// Creates a term with the given coefficient and exponent

public Term (double coefficient, byte exponent)

{ … }

// Evaluates the current term for a given x

public double Evaluate (double x)

{ … }

// Returns -1, 0, or 1 if the exponent of the current term

// is less than, equal to, or greater than the exponent of obj.

public int CompareTo (Object obj)

{ … }

// Read and write properties for each data member

}