Assignment II

Due date Wednesday February 27


1. A bivariate polynomial is a sequence of terms, each of which is a monomial of the form
                  n  m
                Ax  y
where A is a floating point number, and n and m are integers. Each term is described by a record with three components: a coefficient and two exponents. A polynomial is a list of such records. The purpose of this assignment is to write a package to support polynomial manipulation: addition, multiplication, and input/outpout.
This package has the following specification:
    package Polynomials is
       type Term is ...
       type Polynomial is ...
       Null_Polynomial : constant Polynomial := ...
       function "+" (P : Polynomial; T : Term) return Polynomial;
       function "+" (P1, P2 : Polynomial)      return Polynomial;
       function "*" (P : Polynomial; T : Term) return Polynomial;
       function "*" (P1, P2 : Polynomial)      return Polynomial;
       function Read return Term;
       function Read return Polynomial;
       function Write (T : Term);
       function Write (P : Polynomial);
    end Polynomials;
For input, the coefficient and exponents are separated by blanks.

For output, use "^" to mark the exponent. For example, the term (2.2, 3, 2) should be displayed as:
2.2 X ^ 3 Y ^ 2

If the exponent is zero, the corresponding variable and the exponent should not be printed. If the exponent is 1, it should not be printed.

When printing a polynomial, we want to include the sign of the coefficient if it is positive, except for the first term.

You will find it convenient to use the predefined I/O packages, so the body of your package should include the lines:
        with ada.integer_text_io, ada.float_text_io;
        use ada.integer_text_io, ada.float_text_io;
        with Ada.Text_io; use Ada.Text_IO;