# A polynomial of a real valued solution NetBeans Solution

CSE231: Assignment Three

A polynomial of a real valued variable x is an expression of the form a

n

x

n

+ an-1

x

n-1

+ … +

a

1

x

1

+ a0

where a0

, …, a

n

are real constants, called coefficients. For instance, 2.5x

3

+1.2x-5 is

a polynomial of x with a3

=2.5, a2

=0, a1

=1.2 and a0=-5. In this project, you are required to

develop a class named Polynomial that supports symbolic manipulation of polynomials of a

fixed variable x, that is, all polynomials are polynomials of the same variable x. Your class

must at least support operations for

1. Constructing a polynomial given an array of coefficients. For example, given the

float point number array {2.5,0.0,1.2,-5}, the operation constructs a Polynomial

object representing 2.5x

3

+1.2x-5. This is a constructor.

2. Adding one polynomial to another. For example, if this object represents

2.5x

3

+1.2x-5 then adding another object representing 7x

4

+2x

3

+x

2

+3 to this object

changes this object so that it represents 7x

4

+5.5x

3

+x

2

+1.2x–2. Note that the ranks

(the largest exponent) of the two polynomials are not necessary the same.

3. Multiplying one polynomial by another. For example, if this object represents

2x

2

+x-5 then multiplying it by another object representing 3x

3

+x

2

+3 changes this

object so that it represents 6x

5

+5x

4

-14x

3

+x

2

+3x-15. Again the ranks of the two

polynomials are not necessary the same.

4. Evaluating a polynomial for a given value for x. For instance, if this object

represents 2x

2

+x-5 then evaluating it for x=2 yields 5.

5. Converting a Polynomial object to a string so that the Polynomial object can be

displayed. If this object represents 3x

3

+x

2

-1 then the method should return

“3*x^3 + x^2 - 1” although “3*x^3 + 1*x^2 + 0*x^1 + (-1)” is acceptable

1. Specify, design and implement Polynomial. Your implementation must use linked lists

to represent polynomials.

2. Write an interactive test program that tests all the public methods of the Polynomial

class.

Please submit the following.

Analysis: test data;

Design:

1. Class diagrams showing representation of data;

2. A class invariant for each class;

3. Pre/Post conditions for required operations;

4. Algorithms for required operations. Algorithms can be described in English,

flow diagrams, or sequence diagrams;

Code;

Screen snapshots of test runs.

A polynomial of a real valued variable x is an expression of the form a

n

x

n

+ an-1

x

n-1

+ … +

a

1

x

1

+ a0

where a0

, …, a

n

are real constants, called coefficients. For instance, 2.5x

3

+1.2x-5 is

a polynomial of x with a3

=2.5, a2

=0, a1

=1.2 and a0=-5. In this project, you are required to

develop a class named Polynomial that supports symbolic manipulation of polynomials of a

fixed variable x, that is, all polynomials are polynomials of the same variable x. Your class

must at least support operations for

1. Constructing a polynomial given an array of coefficients. For example, given the

float point number array {2.5,0.0,1.2,-5}, the operation constructs a Polynomial

object representing 2.5x

3

+1.2x-5. This is a constructor.

2. Adding one polynomial to another. For example, if this object represents

2.5x

3

+1.2x-5 then adding another object representing 7x

4

+2x

3

+x

2

+3 to this object

changes this object so that it represents 7x

4

+5.5x

3

+x

2

+1.2x–2. Note that the ranks

(the largest exponent) of the two polynomials are not necessary the same.

3. Multiplying one polynomial by another. For example, if this object represents

2x

2

+x-5 then multiplying it by another object representing 3x

3

+x

2

+3 changes this

object so that it represents 6x

5

+5x

4

-14x

3

+x

2

+3x-15. Again the ranks of the two

polynomials are not necessary the same.

4. Evaluating a polynomial for a given value for x. For instance, if this object

represents 2x

2

+x-5 then evaluating it for x=2 yields 5.

5. Converting a Polynomial object to a string so that the Polynomial object can be

displayed. If this object represents 3x

3

+x

2

-1 then the method should return

“3*x^3 + x^2 - 1” although “3*x^3 + 1*x^2 + 0*x^1 + (-1)” is acceptable

1. Specify, design and implement Polynomial. Your implementation must use linked lists

to represent polynomials.

2. Write an interactive test program that tests all the public methods of the Polynomial

class.

Please submit the following.

Analysis: test data;

Design:

1. Class diagrams showing representation of data;

2. A class invariant for each class;

3. Pre/Post conditions for required operations;

4. Algorithms for required operations. Algorithms can be described in English,

flow diagrams, or sequence diagrams;

Code;

Screen snapshots of test runs.

You'll get 1 file (46.1KB)