Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have included the files below; also please make sure the file executes correct

ID: 3665859 • Letter: I

Question

I have included the files below; also please make sure the file executes correctly given the linked files.

Poly0: http://pastebin.com/Cbh7FLW7

Polytest0: http://pastebin.com/V92xPc9R

Polyexam0: http://pastebin.com/ayFFcFPM

The goal of assignment 4 is to reinforce the dynamic classes in C++. Specifically, the assignment is to implement the polynomial class from chapter 4.6 on page 212. But the additional requirement is to implement the class using a dynamic array to store the coefficients. The class needs to have a destructor, copy constructor, and an overloaded assignment operator. The following files are provided for your reference. You should start by modifying the header file first. 1. polyOh: The header file for the preliminary polynomial class. 2. polytest0.cpp: A small interactive test program. 3. polyexam0.cpp: A small non-interactive test program Remember, all those files are only work for static array implementation. You should modify them to make the dynamic array implementation work.

Explanation / Answer

POLYNOMIAL CLASS USING DYNAMIC ARRAY

A polynomial in one variable is an arithmetic expression of the form

anxn + ... + a2x2 + a1x1 + a0

where x is a variable that can take on different numeric values and an , ... , a2 , a1 , and a0 are constants called the coefficients of the polynomial. The highest exponent with non-zero coefficient, n, is called the degree of the polynomial. For example, 0x2 + 2x + 3 is normally written as 2x + 3 and has degree 1. Note that x1 is the same as x, and x0 is 1. A polynomial whose coefficients are all zero has degree -1. Note that a polynomial with degree 2 is called a quadratic polynomial.

One way to represent a polynomial is to use an array to hold the coefficients. A polynomial of degree n has n + 1 coefficients. An array of size k can hold the coefficients for a polynomial of degree k - 1 (or a smaller degree).

Below you will find code for a Polynomial class that uses an array to hold the polynomial coefficients (similar to the List class in section 6.2 of your textbook). It can represent a polynomial of any degree up to and including MAX_DEGREE (a global constant defined with the class). This class has the limitation that all Polynomials have the same "physical size". That is, they all have the same upper limit on the degree. You cannot have a Polynomial with degree larger than MAX_DEGREE.

Your assignment is to make two enhancements to this class. The first is to allow programmers to create Polynomials of any maximum degree. This is accomplished by using a dynamically-allocated array in the class, and by providing a constructor function that allows you to specify the maximum degree. This enhancement is similar to the List class described in section 6.3 of your textbook. The second enhancement is to provide a resize( ) member function that allows the maximum degree of a Polynomial to be changed after it is created. The following paragraphs describe these enhancements in more detail.

Modify the data members of the Polynomial class to use a dynamically-allocated array. You will need to add a data member, say called maxDegree, that stores the maximum degree that a Polynomial object can hold.

The default (no-argument) constructor will create a Polynomial using a dynamically-allocated array large enough to hold a polynomial of a default maximum degree, say called DEF_MAX_DEGREE. Remember that to hold the coefficients of a polynomial of degree n, you need n + 1 coefficients. You will need to add a second constructor to your class that allows the user to create a Polynomial of any maximum degree (this will be an integer parameter). Note: you can combine these into a single constructor by using a default parameter.

As noted in section 6.3 of your textbook, your new class will also need to have a destructor function, a copy constructor, and an overloaded assignment operator.

Add a public member function resize( ) that will increase or decrease the maximum degree of a polynomial. If the maximum degree is decreased, it will never be set smaller than the current degree.

Change the setCoef( ) function so that it will automatically increase the maxDegree of a Polynomial if required (using the resize( ). Be sure to remove the precondition.

Be sure to update the documentation in the class to reflect your changes.

Code for a Polynomial class that uses an array to store the coefficients:

A convenient way to test a class is to use a menu-driven driver. Here is a start on a program to help test your class.