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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, nourmaali
4.11 painting a wall (1) prompt the user to input integers for a wall's height and width. calculate and output the wall's area (integer). note that in this case there is a new line after each prompt. (submit for 1 point). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet (2) extend to also calculate and output the amount of paint in gallons needed to paint the wall (floating point). assume a gallon of paint covers 350 square feet. store this value in a variable. output the amount of paint needed using the %f conversion specifier. (submit for 2 points, so 3 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons (3) extend to also calculate and output the number of 1 gallon cans needed to paint the wall. hint: use a math function to round up to the nearest gallon. (submit for 2 points, so 5 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons
Answers: 3
image
Computers and Technology, 22.06.2019 17:30, kameronstebbins
Which tab should you open to find the option for adding a header?
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, serellehunt
Which type of file can be used to import data into a spreadsheet?
Answers: 1
image
Computers and Technology, 24.06.2019 01:00, arturocarmena10
The initial tableau of a linear programming problem is given. use the simplex method to solve it. x 1 x 2 x 3 s 1 s 2 z 1 2 4 1 0 0 8 3 4 1 0 1 0 10 minus3 minus12 1 0 0 1 0 the maximum is nothing when x 1equals nothing, x 2equals nothing, x 3equals nothing, s 1equals3, and s 2equals0. (be sure to simplify to lowest terms if necessary.)
Answers: 2
You know the right answer?
You are to write a class named Polynomial. In what follows, we do not describe all the implementatio...

Questions in other subjects: