Using dynamic arrays, implement a polynomial class with polynomial addition, subtraction, and multiplication - C++
29.11.2013, 11:27. Просмотров 778. Ответов 0
Вот само задание:
Using dynamic arrays, implement a polynomial class with polynomial addition, subtraction, and multiplication.
Discussion: A variable in a polynomial does nothing but act as a placeholder for the coefficients. Hence, the only interesting thing about polynomials is the array of coefficients and the corresponding exponent. Think about the polynomial x^3+x+1, what is the coefficient of term x^2 ? One simple way to implement the polynomial class is to use an array of doubles to store the coefficients. The index of the array is the exponent of the corresponding term. If a term is missing, then it simply has a zero coefficient.
Provide a default constructor, a copy constructor, and a parameterized constructor that enables an arbitrary polynomial to be constructed.
Supply an overloaded operator = and a destructor.
Provide these operations:
polynomial + polynomial, constant + polynomial, polynomial + constant,
polynomial – polynomial, constant – polynomial, polynomial – constant,
polynomial * polynomial, constant * polynomial, polynomial * constant,
Supply functions to assign and extract coefficients, indexed by exponent.
Supply a function to evaluate the polynomial at a value of type double.
A sample testing code will be provided for your reference. But your implemention doesn't have to match exactly my testing code. If your choice of implementing a function as a member, a friend, or a standalone function is different as mine, please comment it in your assignment and provide your own testing code.