a.out polynomials.dat operations.dat
A polynomial in one variable is composed of terms, where each term has both
a coefficient and an exponent. An example of a polynomial is:
x³ + 3x² - 5x + 6
where, the standard form of expression is that the terms are in descending order by the exponent of x. It is also standard to eliminate the terms that have a coefficient of 0. A detailed explanation of the terms is as follows:
The first term, x³, has an implied coefficient of 1 and the
exponent is 3.
The second term, 3x², has a coefficient of 3 and the exponent is
2.
NOTE: The operator between the first and second term gives the sign of
the coefficient for the second term. In this case the operator is +,
indicating a coefficient of positive 3.
The third term, 5x, has a coefficient of -5 since the operator
preceding this term is -. The exponent is an implied 1.
The last term of the example polynomial is 6. This is the coefficient
and it is positive due to the + operator preceding it. The exponent of x is 0.
By definition, anything taken to the 0th power is 1. So the coefficient is
6 and it is to be multiplied by 1, resulting in 6.
Notice how many times I used the word "implied" in the discussion about
polynomials above. People tend to have little trouble interpreting implied
things, but computers don't do as well. For that reason, we will use a
different format for expressing our polynomials. Nothing will be implied
about any term. Of course, it won't look as nice. Here's how I will
express this same polynomial in the data file:
The two data files are shown below. The polynomials.dat file, begins by giving the number of polynomials present in the file. Each of the polynomials is on a seperate line. The terms of the polynomial are made up of coefficient and exponent pairs, as explained previously. The terms in the polynomial may, or may not, be in descending sorted order by exponent.
The operations.dat file gives a list of operations to be performed on a specified polynomial or polynomial pair.
The executable and the data files need to be in the same directory in order to work properly.