The deadline for this lab is Wednesday 09 November 2005, 09:45 hours. Strictly no submissions will be accepted after the deadline.
anxn + an-1xn-1 + an-2xn-2 + ... + a2x2 + a1x + a0
For simplicity, we assume that all the coefficients a0, a1, ..., an are integers. The above equation has degree n. We assume that a polynomial will have a maximum degree of 9, and we will be able to store a maximum of 10 polynomials.
We wish to implement the following functions:
1 0 2 7 8 9 1 1 3 2 -3 -1 4 2 1 2 3 0 1 3 4 0 1 4 2 1 7 5 0 1 7 0
We will look at each line in turn.
1 0 2 7 8 9
1: indicates we want to store a polynomial.
0: indicates we store it at slot 0. If there is an existing
polynomial at slot 0, it is overwritten.
2: indicates the degree of the polynomial.
7 8 9: indicates the coefficients of the polynomial, starting
from the highest degree. This represents the polynomial 7x2 +
8x + 9.
1 1 3 2 -3 -1 4
1: indicates we want to store a polynomial.
1: indicates we store it at slot 1. If there is an existing
polynomial at slot 1, it is overwritten.
3: indicates the degree of the polynomial.
2 -3 -1 4: indicates the coefficients of the polynomial,
starting from the highest degree. This represents the polynomial
2x3 - 3x2 - x + 4.
2 1 2
2: indicates we want to differentiate a polynomial with respect
to x.
1: indicates we want to differentiate the polynomial at slot 1.
2: indicates we want to store the result at slot 2.
For those who forgot how to do differentiating: Differentiating axn with respect to x gives the result: naxn-1
3 0 1 3
3: indicates we want to add two polynomials.
0 1: indicates we want to add the two polynomials at slots 0
and 1.
3: indicates we want to store the result at slot 3.
4 0 1 4
4: indicates we want to subtract the second polynomial from the
first polynomial.
0 1: suppose f0(x) is the polynomial at slot 0, and
suppose f1(x) is the polynomial at slot 1. We want to
calculate f0(x) - f1(x).
4: indicates we want to store the result at slot 4.
2 1 7
Indicates we want to differentiate the polynomial at slot 1 and store the result at slot 7.
5 0 1 7
5: indicates we want to multiply two polynomials.
0 1: indicates we want to multiply the two polynomials at slots 0
and 1.
7: indicates we want to store the result at slot 7. The
existing polynomial at slot 7 is overwritten.
0
0: indicates we want to exit the program.
You may also assume that all numbers in the text file are valid integers. It is possible for a coefficient to be zero. No error checking is required.
After processing all the commands, display the polynomials at all ten slots. If a slot does not contain any polynomial, just display a blank line, as shown below. If a term's coefficients is zero, do not display the term.
Poly #0: (7)x^2 + (8)x^1 + (9)x^0 Poly #1: (2)x^3 + (-3)x^2 + (-1)x^1 + (4)x^0 Poly #2: (6)x^2 + (-6)x^1 + (-1)x^0 Poly #3: (2)x^3 + (4)x^2 + (7)x^1 + (13)x^0 Poly #4: (-2)x^3 + (10)x^2 + (9)x^1 + (5)x^0 Poly #5: Poly #6: Poly #7: (14)x^5 + (-5)x^4 + (-13)x^3 + (-7)x^2 + (23)x^1 + (36)x^0 Poly #8: Poly #9:You are reminded to follow the sample output exactly; else marks will be deducted.
Remember to submit your program using the submit poly.c command, and check your submission using the check command.
All the best!