A polynomial may be represented as a linked list where each node contains the coefficient and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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) 18X³7X³ +6X² +6 8X³7X+ +6X³+ 9X²8X+9 26X³7X -X³ + 15X² -8X+15 A) Equationl : Equation2: Result: B) Equation1: Equation2: Result: C) Equationl : Equation2: Result: 8X³-7X5+6X² +6 8X³7X² +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); 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) 18X³7X³ +6X² +6 8X³7X+ +6X³+ 9X²8X+9 26X³7X -X³ + 15X² -8X+15 A) Equationl : Equation2: Result: B) Equation1: Equation2: Result: C) Equationl : Equation2: Result: 8X³-7X5+6X² +6 8X³7X² +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);
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
you will be asked to put together a series of written communication that focuses on positive messaging for a variety of audiences. You will write a(n) E-mail encouraging employees to be more...
-
For the current year, Conres Corp., a CCPC, has aggregate investment income (AII) of $110,000 and taxable income of $400,000, of which $290,000 is eligible for the SBD. Federal Part I tax is $68,633....
-
The second programming project involves writing a program that examines a file of polynomials and determines whether the polynomials in that file are in strictly ascending order using two different...
-
Which set of parametric equations is shown in the graph below? Explain your reasoning. (a) (b) x = t y = f
-
Name five major activities of an OS with respect to process management, and briefly describe why each is required.
-
Give the number of protons and electrons in each of the following common ions: Na+, Ca2+, Al3+, Fe2+, I-, F-, S2-, O2-, and N3-.
-
What setting should the technician use to capture the maximum vibration at every speed during a coast-down?
-
Great Taste Food Stores operates 20 large supermarkets in the East. Each store is evaluated as a profit center, and store managers have complete control over their purchases and inventory policy....
-
1. The fighters of the Ultimate Fighting Championship (UFC) filed suit against the UFC, alleging that the UFC unlawfully monopolized the output and input markets in mixed martial arts. In particular,...
-
1. 19 of 22 participants (86.36%) from the high-power posing group took a gambling risk to double their money, while 12 of 20 (60%) from the low-power posing group took the gambling risk. Use a...
-
Sometimes, co-workers complain to their supervisor that other associates are always talking in the native language, concerned they may be creating a disruption. The fact remains that our workforce is...
-
Remo Company and Angelo Incorporated are separate companies that operate in the same industry. Following are variable costing income statements for the two companies showing their different cost...
-
What common mistakes do students use that can lead to plagiarism? What steps can you take as a speaker to ensure you are practicing ethical speechmaking?
-
If you were to borrow $8,600 over five years at0.12 compounded monthly, what would be your monthly payment?
-
What is the difference between regarding businesses as development agents, and regarding them as development tools (Blow field & Murray, 2014)? Explain this in relation to at least one example you...
-
How do experiences of privilege and marginalization intersect within individuals' lives, and how can recognizing these intersections inform strategies for allyship and coalition-building across...
-
A particle starts from rest and moves with acceleration & and then with retardation & and finally comes to rest. If total distance moved is S. Calculate max. speed attained. Calculate average speed,
-
The May 2014 revenue and cost information for Houston Outfitters, Inc. follow: Sales Revenue (at standard).............. $ 540,000 Cost of Goods Sold (at standard) ..........341,000 Direct Materials...
-
Write a program that reads a bank account balance and an interest rate and displays the value of the account in ten years. The output should show the value of the account for three different methods...
-
Write a program that uses the Purchase class in Listing 5.13 to set the following prices: Oranges: 10 for $2.99 Eggs: 12 for $1.69 Apples: 3 for $1.00 Watermelons: $4.39 each Bagels: 6 for $3.50 Then...
-
Repeat Exercise 18 in Chapter 1, but define and use named constants. Exercise 18 Write statements that can be used in a JavaFX application to draw the five interlocking rings that are the symbol of...
-
Define internal combustion engine and explain how it is different from external combustion engines?
-
In an air standard Otto cycle, the pressure and temperature at the start of compression stroke are 1 bar and \(30^{\circ} \mathrm{C}\), respectively. The temperature at the end of compression is...
-
In I.C. engines, power developed inside the cylinder is known as: (a) Brake horse power (b) Indicated horse power (c) Pumping power (d) None of the above
Study smarter with the SolutionInn App