Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   Write a program to Overload the addition operator (+) to add two Polynomials. (https://www.askmehelpdesk.com/showthread.php?t=529118)

  • Nov 26, 2010, 02:42 AM
    fiza_murtaza
    write a program to Overload the addition operator (+) to add two Polynomials.
    Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The term 2x4
    has a coefficient of 2 and an exponent of 4. Develop a full class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities:
    a) Overload the addition operator (+) to add two Polynomials.
    b) Overload the subtraction operator (-) to subtract two Polynomials.
    c) Overload the assignment operator (=) to assign one Polynomial to another.
    d) Overload the multiplication operator (*) to multiply two Polynomials.

    Sample output:


    Enter number of polynomial terms: 2
    Enter coefficient: 2
    Enter exponent: 2
    Enter coefficient: 3
    Enter exponent: 3
    Enter number of polynomial terms: 3
    Enter coefficient: 1
    Enter exponent: 1
    Enter coefficient: 2
    Enter exponent: 2
    Enter coefficient: 3
    Enter exponent: 3
    First polynomial is:
    2x^2+3x^3
    Second polynomial is:
    1x+2x^2+3x^3
    Adding the polynomials yields:
    1x+4x^2+6x^3
    Subtracting the polynomials yields:
    -1x
    Multiplying the polynomials yields:
    2x^3+7x^4+12x^5+9x^6 class Polynomial

  • All times are GMT -7. The time now is 06:52 PM.