Program 3

Polynomial Calculator

due Thursday, March 10, 2005 by the start of your lab period

Lab Partners

Everyone is encouraged to work with one lab partner on this assignment. If you do work with a partner, submit one solution with both of your names on it. Also, please look at the class collaboration policy so that you know what is and what isn't allowed.

Introduction

In this program, we are going to construct a tool that can be used to manipulate two polynomials. Specifically, we are interested in being able to add two polynomials and to multiply two polynomials.

Provide the user a text-based menu (or optionally, a GUI) with the following options:

  1. The user should be able to enter a value for polynomial 1. Initially, polynomial 1 is 0. You may assume that the user will only enter valid polynomials according to the rules below.
  2. The user should be able to enter a value for polynomial 2. Initially, polynomial 2 is 0. You may assume that the user will only enter valid polynomials according to the rules below.
  3. The user should be able to add the two polynomials and print the result of the addition.
  4. The user should be able to multiply the two polynomials and print the result of the multiplication.
  5. The user should be able to quit.

Terminology

Consider the polynomial 3n^2 - 11n^1. 3n^2 is a term as is - 11n^1. 3 and -11 are coefficients. 2 and 1 and degrees.

Input/Output Format for a Polynomial

When a polynomial is input or printed, only non-zero coefficients should appear. The terms of the polynomial should appear in descending degree order. Here are three examples of legal polynomials:

Here are four examples of illegal polynomials:

Your program may assume that all "+"s and "-"s are surrounded by one or more empty spaces. Your program may also assume that the only variable that appears in a polynomial is n.

One Example

Required Representation

You must have a class named Polynomial that represents a polynomial using a linked list. You may either use a built-in linked list class or you may implement your own.

Grading

What to Submit

E-mail your code to Mike Thiesen at mthiesen@gmail.com in one message before the due date. Zip your relevant BlueJ folder up so that you only need to send Mike one file. The subject of the message should be: CS221-xx program3 your-names. The xx is the number of your lab section. Late programs will not be accepted for credit. If you aren't finished by the deadline, submit whatever you have - partial credit is possible.