subject

You are to write a class named Polynomial. In what follows, we do not describe all the implementation details, but just provide the main functionality that must be provided by the class. Your class will be tested using this
functionality. If it is indicated that you MUST use a structure or perform a certain task in the class or in a function, do
so. Otherwise, you are free to make the choice by yourself. Of course, you are expected to perform good
programming practices of object oriented programming, e. g. conforming data encapsulation principle.
IMPORTANT: Recall how to allocate pointers to objects by using the keyword new along with a constructor.
(1) An object of the class Polynomial represents a mathematical polynomial in the usual sense. Here are some
examples of polynomials expressed by starting from the exponent 0 (which represents the constant of the
polynomial) and listing the terms in ascending exponents:
3 + x + x^3 + 7*x^6
x^2 + 1000*x^4
Here x^k represents x raised to the power k, and * is the multiplication operator. Note that when the coefficient of
a specific term is 0, we do not list it for saving space. Thus, for example, the second polynomial above is in fact
0 + 0*x + x^2 + 0*x^3 + 1000*x^4
But we only list the two non-zero terms. Note also that we do not write the coefficient and exponent 1.
(2) The class Polynomial MUST keep vector objects of C++ to represent a polynomial as above. You may
assume that the coefficients of the polynomial are integers. Note that in order to represent a term, you must keep
both the exponent and the coefficient. Thus, it might be a good idea to use two different data structures, one for
exponents, and one for coefficients. For example, the second polynomial above might have the values [2, 4] in the
exponents vector, and [1, 1000] in the coefficients vector.
Provide two constructors, the default constructor creating the 0 polynomial, and the other taking two vectors
(exponents and coefficients) representing the polynomial. Do not forget the destructor.
(3) The class Polynomial has the following member function
Polynomial *add(Polynomial *p1, Polynomial *p2);
It adds the polynomials represented by p1 and p2, and returns a new Polynomial object representing the result.
Please, BE CAREFUL: You should not represent the terms with coefficient 0. Furthermore, if there are terms in one
polynomial not appearing in the other, you may have to create new terms in the result.
(4) The class Polynomial has the following member function
Polynomial *subtract(Polynomial *p1, Polynomial *p2);
It subtracts the polynomial p2 from p1, and returns a new Polynomial object representing the result. [Hint:
This is easy once you implement add].(5) The class Polynomial has the following member function
Polynomial *multiply(Polynomial *p1, Polynomial *p2);
It multiplies the polynomials represented by p1 and p2, and returns a new Polynomial object representing the
result. Please, BE CAREFUL: Multiplication of polynomials are more complicated than addition. If you do not know
how to do this, please learn it from an appropriate source. This is usually taught in high school.
(6) The class Polynomial has the following member function
string toString();
This prints out the underlying Polynomial object, based on the information contained in the vectors0, in the
format given in 1).

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:30
What do character formats do for your document's message? a.set the tone b.provide organization c.provide clarity d.set how texts align with documents
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Quic which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 24.06.2019 06:30
For which utilities, if any, does the landlord pay?
Answers: 2
question
Computers and Technology, 24.06.2019 16:00
Your is an example of personal information that you should keep private.
Answers: 1
You know the right answer?
You are to write a class named Polynomial. In what follows, we do not describe all the implementatio...
Questions
question
Physics, 11.10.2019 10:50
Questions on the website: 13722363