Linked List Representation of Polynomials ( Due 03 Apr 2023 )

A polynomial is of the form:

anxn + an - 1xn - 1 + … + a1x1 + a0x0

We are going to assume that the polynomials that we will be representing will have integer coefficients and exponents. The coefficients can be positive or negative. The zero-coefficient terms are not shown in the polynomial expression. The exponents are zero or greater.

In this assignment you will represent a polynomial as a Linked List. You will redefine the Link class and then work on the Linked List class. You will implement two main arithmetical functions on polynomials - addition and multiplication. You may add as many helper functions as needed.

Input: You will read input from a file poly.in. You will have data for just two polynomials separated by a single blank line. The first line of data will be n the number of terms in the first polynomial having non-zero coefficients. It will be followed by n lines of data. Each line having two integers separated by two or more spaces. The first integer will be the coefficient and the second integer will be the exponent. It will be followed by blank line. This will be followed by a single integer m representing the number of non-zero coefficient terms in the second polynomial. It will be followed by m lines. Each line will have two integers separated by one or more spaces representing the coefficient and exponent.

Output: Your output will be the sum and product of the two polynomials in the following format:

Sum: (3, 4) + (3, 3) + (5, 2) + (-6, 1) + (2, 0)

Product: (15, 7) + (-10, 6) + (7, 5) + (18, 4) + (-34, 3) + (10, 2)
Both the sum and the product will be in descending order of the exponents. There should not be any zero coefficient term in the output.

Here is the template of the code:

import sys

class Link (object):
  def __init__ (self, coeff = 1, exp = 1, next = None):
    self.coeff = coeff
	self.exp = exp
	self.next = next

  def __str__ (self):
    return '(' + str (self.coeff) + ', ' + str (self.exp) + ')'

class LinkedList (object):
  def __init__ (self):
    self.first = None

  # keep Links in descending order of exponents
  def insert_in_order (self, coeff, exp):

  # add polynomial p to this polynomial and return the sum
  def add (self, p):

  # multiply polynomial p to this polynomial and return the product
  def mult (self, p):

  # create a string representation of the polynomial
  def __str__ (self):

def main():
  # read data from file poly.in from stdin

  # create polynomial p

  # create polynomial q

  # get sum of p and q and print sum

  # get product of p and q and print product

if __name__ == "__main__":
  main()

For this assignment you may work with a partner. Both of you must read the paper on Pair Programming. .

The file that you will be uploading will be called Poly.py. We are looking for clean and structured design. The file will have a header of the following form:

#  File: Poly.py

#  Description:

#  Student Name:

#  Student UT EID:

#  Partner Name:

#  Partner UT EID:

#  Course Name: CS 313E

#  Unique Number: 

#  Date Created:

#  Date Last Modified:

If you are working with a partner then only one of you will submit the code. Make sure that in the header you have your name and UT EID and your partner's name and UT EID. You must use the group submission feature on Gradescope and mention your partner by name. If you are working alone then you will just have your name and your UT EID in the header.

Use the Canvas system to submit your Poly.py file. We should receive your work by 11 PM on Monday, 03 Apr 2023. There will be substantial penalties if you do not adhere to the guidelines. Remember Python is case sensitive. The name of your file must match exactly what we have specified.