Homework 4
Short Description:
Implement a simple sparse polynomial class.
This assignment is worth 10 points.
Goals
When you finish this homework, you should:
- Gain experience working with the list class.
- Implement the basic algorithms for addition, subtraction
multiplication and division.
Formal Description
Implement a polynomial class. You should assume that the polynomials
are sparse, and therefore you should store the polynomials in a list.
You MUST use the STL list class to do this. For each term in the polynomial
store the coefficient and the exponent. Thus 3x14+2x+1 would be
stored as
3,14-> 2,1 -> 1,0
Your class should support the following operations:
- Creation and deletion.
- +, -, *, / - each of these returns a new polynomial
- <<
- addTerm(double coeff,int exp) - add a term to the current polynomial
- evaluate(double x) - returns a double, f(x)
- dx - returns the first derivative of the polynomial
You should write a driver routine that tests all of these functions.
Input
Output
Discussion
Required Files
Your code, a README file , and a Makefile.
Extra Credit
If you wish, you may gain 10 points extra credit by finding all of the
roots of a polynomial. Write a program that reads in a polynomial from the
user and prints all of the roots.
Submission
This assignment is due October 31 at class time. You should email a tar file
of your homework directory to dbennett@edinboro.edu.