11001 - Polynomial(operator overloading)   

Description

Description

Develop 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.

Develop a complete class containing proper constructor functions. The class should also provide the following overloaded operator capabilities:

  1. Overload the addition operator (+) to add two polynomials.
  2. Overload the subtraction operator (-) to subtract two polynomials.
  3. Overload the multiplication operator (*) to multiply two polynomials.
  4. Overload the stream insertion operator (<<).

Note:

1.      This problem involves two files.

      •   function.h: Class definition of Polynomial.

      •   main.cpp: A driver program to test your class implementation.

You will be provided with main.cpp and function.h, and asked to implement 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

11001.cpp

Partial Judge Header

11001.h

Tags

10402HW7



Discuss