CS 1723 Section 1T, Summer 1998 Assignment 4

Polynomial Differentiation

Your assignment is to complete a program that accepts a polynomial in one variable (x) on standard input and prints its first derivative on standard output. Input will be plain text, using ^ for the exponentiation operator (e.g., x^2 is x2). For example, if the input is:
2x^7 - 4x^4 + 3x^2 - 4
then the output should be:
14x^6 - 16x^3 + 6x
On the runner system, in directory ~djimenez/cs1723/diff (the full path is /home/staff3/djimenez/cs1723/diff) you will find a Makefile and several .h and .c files that combine to read, construct, and print polynomials as linked lists of terms called monomials. Each monomial is something like 2x7 and is represented as a struct like this:
typedef struct _mono {
	double	coeff, power;
} mono;
where coeff is the coefficient x is multiplied by and power is the exponent x is raised to. Note that a zero power implies a constant (i.e., coeff time x0), and a zero coefficient implies the entire term is zero and should be left out of the polynomial.

The file calc.c contains a driver program that reads in a polynomial as a linked list (so you don't have to worry about how to do that), prints the polynomial on the screen (again, you don't have to do that), calls a function you will write to differentiate the polynomial, then prints the derivative.

The file mono.h contains declarations for the mono struct above and declarations used by a file called mono.c that reads in terms; this C file is only used internally and you don't need to look at it.

The file poly.h declares an abstract data type poly for polynomials. poly is a pointer type to a linked list of mono terms. Some functions declared in this file and defined in poly.c are:

The file diff.h declares a single function, poly differentiate (poly);. Your assignment is to write this function. It accepts poly linked list and returns a new poly linked list (without modifying the old one) that contains the derivative. You should write this function (and any support functions you will need) in a file called diff.c. An empty diff.c is provided that just returns NULL so that you can get everything compiled before you get everything working.

To Do This Assignment

Extra Credit

This assignment is worth 10 points. The following options are available for up to 5 points extra credit: This program is due by midnight, Tuesday, June 23, 1998.