Copyright © – Sudharsan Iyengar

 

CS – 341: Lab 2                     Fall 2024             Sudharsan Iyengar               8/29/2024

 

Polynomial Operations:

 

You are required to write an application that will perform polynomial operations. A polynomial is of the form

 

            AnXn + An-1Xn-1+ ……+ A1X+A0

 

Where A0, A1, …., An-1, An are constants and X is a variable.

 

Design and develop a class Polynomial which will be used to store a polynomial as described above.

 

Write an application that will create and store polynomials and provide user with menu driven options to chose polynomials, and perform operations on those polynomials (and output the result), repetitively until the user chooses exit.

 

            Select and Evaluate a Polynomial, given an input value (int)

            Select and add two Polynomials and display the result polynomial

 

The polynomials are described in an input file poly.dat using the following format:

           

            Each line has a polynomial name and then the polynomial using pairs of integers – each pair representing a term in the polynomial.

 

            Example poly.dat file.

 

                        6 3 4 1 2 0

                        10 12 18 6 -4 2 1 1

                        4 1 -20 0

 

            This file describes 3 polynomials. The first one is 6X3 + 4X + 2, the second one is 10X12+ 18X6 – 4X2 + X, and the third one is 4X – 20.

 

You can output a polynomial read from the file and the results of operations as follows:   

 

                        10X^12 + 18X^6 - 4X^2 + X