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

Write a program that adds and subtracts polynomials. Each polynomial is to be re

ID: 3619066 • Letter: W

Question

Write a program that adds and subtracts polynomials. Each polynomial is to be represented as a linked list. The first node in the list represents the first term in the polynomial, the second node represents the second term, and so forth. Each node contains three fields. The first field is the term's coefficient. The second field is the term's power. The third field is a pointer to the next term. The rules for addition of the polynomial are as follows: If the two powers are equal, the coefficients are added. If the two powers are unequal, the term with the higher power is inserted in the Result polynomial. If the exponent is 0, it represent x degree , which is 1. The value of the term is therefore the value of the coefficient. If the result of adding the coefficients results is 0, the term is dropped.

Explanation / Answer

x.P5 #include #include #include struct node {      int coeff;          int power;         node *nxt; }; node *start_ptr1 = NULL; node *start_ptr2 = NULL; int option = 0; //Adding the a new node to the list void add_node_at_end(int list) {      node *temp, *temp2,*start_ptr;         temp = new node;      cout > temp->coeff;      cout > temp->power;        temp->nxt = NULL;      if(list == 1)      {           if (start_ptr1 == NULL)           {             start_ptr1 = temp;           }           else           {             temp2 = start_ptr1;             while (temp2->nxt != NULL)             {                temp2 = temp2->nxt;             }             temp2->nxt = temp;           }      }      else      {          if (start_ptr2 == NULL)           {             start_ptr2= temp;           }           else           {             temp2 = start_ptr2;             while (temp2->nxt != NULL)             {                temp2 = temp2->nxt;             }             temp2->nxt = temp;          }      } } //Displaying the list void display_list(int list, int sign) {      node *temp;      if(list == 1)           temp = start_ptr1;      else            temp = start_ptr2;          //cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote