SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Pointers And Linked Lists
Exercise:
Programming Projects
Question:3 | ISBN:9780321531346 | Edition: 7

Question

Design and implement a class whose objects represent polynomials. The

Polynomial an x n + an–1x n–1 + . . . + a0

will be implemented as a linked list. Each node will contain an int value

for the power of x and an int value for the corresponding coefficient. The

class operations should include addition, subtraction, multiplication, and

evaluation of a polynomial. Overload the operators +, , and * for

addition, subtraction, and multiplication.

Evaluation of a polynomial is implemented as a member function with

one argument of type int. The evaluation member function returns the

value obtained by plugging in its argument for x and performing the

indicated operations. Include four constructors: a default constructor, a

copy constructor, a constructor with a single argument of type int that

produces the polynomial that has only one constant term that is equal to the

constructor argument, and a constructor with two arguments of type int

that produces the one-term polynomial whose coefficient and exponent are

given by the two arguments. (In the above notation, the polynomial

produced by the one-argument constructor is of the simple form consisting

of only a0. The polynomial produced by the two-argument constructor is of

the slightly more complicated form anx n.) Include a suitable destructor.

Include member functions to input and output polynomials.

When the user inputs a polynomial, the user types in the following:

anx ^n + an–1x ^n–1 + . . . + a0

However, if a coefficient ai is zero, the user may omit the term aix^i. For

example, the polynomial

3x4 + 7x2 + 5

can be input as

3x^4 + 7x^2 + 5

It could also be input as

3x^4 + 0x^3 + 7x^2 + 0x^1 + 5

If a coefficient is negative, a minus sign is used in place of a plus sign, as

in the following examples:

3x^5 – 7x^3 + 2x^1 – 8

7x^4 + 5x^2 + 9

A minus sign at the front of the polynomial, as in the second of the two

examples, applies only to the first coefficient; it does not negate the entire

polynomial. Polynomials are output in the same format. In the case of

output, the terms with zero coefficients are not output.

To simplify input, you can assume that polynomials are always entered

one per line and that there will always be a constant term a0. If there is no

constant term, the user enters zero for the constant term, as in the

following:

12x^8 + 3x^2 + 0

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.