10993 - Polynomial class   

Description

Create a class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent, e.g., the term 2x4 has the coefficient 2 and the exponent 4.

  • Use a 51-element array, coefficients, of digits to store each coefficient.
  • Use a integer variable, greatestPower, to store an exponent.

 

Provide public member functions that perform each of the following tasks:

  1. Adding two Polynomial.
  2. Subtracting two Polynomial.
  3. Multiplying two Polynomial.
  4. Printing coefficients of the Polynomial in descending order.

 

Note:

1.      This problem involves three files.

  • function.h: Class definition of Polynomial.
  • function.cpp: Member-function definitions of Polynomial.
  • main.cpp: A driver program to test your class implementation.

You will be provided with main.cpp, and asked to implement function.h and function.cpp.

function.h

main.cpp

2.     For OJ submission:

       Step 1. Submit only your function.cpp into the submission block.

       (***Note that you don’t need to submit your function.h.)

       Step 2. Check the results and debug your program if necessary.

Input

There are four lines.

The first two lines represent the greatest power and the corresponding coefficients of the first polynomial.

The last two lines represent the greatest power and the corresponding coefficients of the second polynomial.

Note that the coefficients are in descending order and each element is separated by a blank.

Output

Your program should print the coefficients of the sum, difference and product of these two polynomials in descending order, respectively.

Note that every answer should be followed by a new line character.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

10993.cpp

Partial Judge Header

10993.h

Tags

10402HW5



Discuss