Question: A polynomial may be represented as a linked list where each node contains the coefficient and exponent of a term of the polynomial. The

A polynomial may be represented as a linked list where each node contains the coefficient and exponent of aTest run for the following inputs (Do not change the order of exponent in the input file) 18X7X +6X +6 8X7X+struct nodetype { int coeff; int exp; nodetype *next; class equation { private: public: }; nodetype *begin,

A polynomial may be represented as a linked list where each node contains the coefficient and exponent of a term of the polynomial. The polynomial 4 X -3 X-5 would be represented as a linked list given below. Equation1 4 3 -3 2 -5 0 Write a COMPLETE program that reads two polynomials in any order of exponent from an input file, stores them as sorted (in the descending order of the exponents) linked lists, adds them together, and prints the result as a polynomial to an output file. The result should be a third linked list. Hint: Travers both polynomials. If a particular exponent value is present in either of the two polynomials being summed, then it should be present in the answer. If it is present in both polynomials, then its coefficient is the sum of the corresponding coefficient in both polynomials. (If this sum is zero, the term should be deleted). KEYWORDS: Classes Pointers NOTE: Must write a very general program using Object oriented concept. Do not use any library functions. All methods used in the program MUST be written in C++ and included in the program. Test run for the following inputs (Do not change the order of exponent in the input file) 18X7X +6X +6 8X7X+ +6X+ 9X8X+9 26X7X -X + 15X -8X+15 A) Equationl : Equation2: Result: B) Equation1: Equation2: Result: C) Equationl : Equation2: Result: 8X-7X5+6X +6 8X7X +6X +9X-8 X +6X+ +17X-X -2 8x - 6+5X +6X + 8X 7X +6X 9X - 6X +5X*+18X-9 8x - 7X7 +14X +5X +26X + 6X-15 struct nodetype { int coeff; int exp; nodetype *next; class equation { private: public: }; nodetype *begin, *last; int length; //Default constructor equation(); // Method to insert an item in the linked list in a sorted order void insertitem( nodetype temp); // Method to output all the items in the linked list void printlist(); // Method to add two equaition equation add(equation e2);

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!