Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Polynomial multiplication (C++) Start with the polynomial.cpp file provided. Thi

ID: 3692227 • Letter: P

Question

Polynomial multiplication (C++)

Start with the polynomial.cpp file provided. This is a basic outline of the class, which reads the in the polynomial from the keyboard. You must overload the multiplication operator to multiply polynomials together (i.e. FOIL arbitrary dimension polynomials). Also overload for cout and make sure you follow the formatting shown below exactly. The program provided has no memory leaks, and your submission should not not leak memory as well. In other words, if you create dynamic memory you also need to delete it somewhere in the code. [Hint: What is the relationship to the index and the power of “x”?]

Example 1 (user input is underlined):

What are the coefficients of first polynomial (lowest power first)? 1 2 3

What are the coefficients of second polynomial (lowest power first)? 4 5 6

(1) + (2)x^1 + (3)x^2

... times...

(4) + (5)x^1 + (6)x^2 ­­­­­­­­­­­­

(4) + (13)x^1 + (28)x^2 + (27)x^3 + (18)x^4

Example 2 (user input is underlined):

What are the coefficients of first polynomial (lowest power first)? 1 ­-2 1

What are the coefficients of second polynomial (lowest power first)? ­-1

(1) + (­-2)x^1 + (1)x^2

... times...

(­-1) ­­­­­­­­­­­­

(-­1) + (2)x^1 + (-­1)x^2

Example 3 (user input is underlined):

What are the coefficients of first polynomial (lowest power first)? 1 2 3 4 5

What are the coefficients of second polynomial (lowest power first)? 1 -­2 1 -­4

(1) + (2)x^1 + (3)x^2 + (4)x^3 + (5)x^4

... times...

(1) + (-­2)x^1 + (1)x^2 + (­-4)x^3 ­­­­­­­­­­­­

(1) + (0)x^1 + (0)x^2 + (­-4)x^3 + (­-8)x^4 + (­-18)x^5 + (-­11)x^6 + (­-20)x^7

polynomial.cpp:

Explanation / Answer

#include #include #include struct polynomial{ int coefficient; int power; poly *next; }; class multiply2polynomial { polynomial *poly1, *poly2, *poly3; public: muliply2polynomial(){poly1=poly2=poly3=NULL;} void multiplypoly(); void displaypplynomials(); }; void muliply2polynomial :: multiplypoly(){ int i,p; polynomial *newl=NULL,*end=NULL; coutp; //first we will read the first polynomial coutpower=i; coutpower){ newl=new polynomial; newl->power=p1->power + p2->power; newl->coefficient=p1->coefficient * p2->coefficient; newl->next=NULL; if(poly3==NULL) poly3=newl; else{ flag=1; // now we will search if the element already exists in polynomial3 polynomial *temp=poly3; while(temp!=NULL){ if(temp->power==newl->power){ temp->coefficient += newl->coefficient; flag=0; } temp=temp->next; } //however if the item not present simply append it.if(flag==1) end->next=newl; } end=newl; p2=p2->next; } p1=p1->next; } } void multiply2polynomial :: displaypolynomials(){ poly *z=poly3; cout