UE CS 215 - CS 215 ­ Fundamentals of Programming II Project 3

Unformatted text preview:

CS 215 - Fundamentals of Programming IIFall 2010 - Project 330 pointsOut: September 20, 2010Due: October 1, 2010 (Friday)A polynomial is a mathematical expression involving a sum of powers in one or more variables multiplied by coefficients. A polynomial of degree n in one variable with constant coefficients is given bycnxn + cn-1xn-1 + ... + c1x + c0Generally the terms where the real number coefficients ci are 0 are not displayed, except for the polynomial of a single constant term of value 0. There are various implementation of polynomials. For this assignment, we will represent a polynomial using a vector of doubles where the value at index i is the coefficient ci of the term cixi. (Note: if a polynomial is sparse and its degree is high, this representation wastes a lot of space storing the 0 coefficients. E.g., x99 + 1 would require a vector of 100 elements, 98 of which would be 0. We will address this issue in a later project.)Specification for Polynomial ClassData Attributes Object Type Namevector of coefficients vector<double> coefficientsThe invariant for this class is ● the value at index i of the coefficients vector is the coefficient ci of the term cixi.● the last element of the coefficients vector, which represents the polynomial term with the highest degree, is not 0, unless there is only one element. A single element with value 0 represents the constant term 0.Operations ● Default constructor - creates a polynomial of one constant term with coefficient 0.Analysis – no parameters● Explicit-value constructor - creates a polynomial from a vector of coefficients and a vector of exponents. You should assume that both vectors are the same size and that the exponents are in decreasing order. (I.e., you do not need to do error checking or sort the terms.) The ith coefficient is matched with the ith power to specify a term of the polynomial. If the vectors are empty, the constructed polynomial should be the constant term 0 value.Analysis Objects Type Movement Namevector of coefficients vector<double> received initialCoefficientsvector of exponents vector<int> received initialExponentsTypos fixed 09/28/2010 Page 1 of 4 D.Hwang● Degree - returns the highest exponent of the polynomialAnalysisObjects Type Movement Namehighest exponent int returned -------● Evaluate - evaluate the polynomial at particular point, return the result Analysis Objects Type Movement Namepoint of evaluation double received xresult of evaluation double returned result● operator+ - friend overloaded arithmetic operator+. Returns a Polynomial object that is the sum of the parameters. The terms of the sum of two polynomials is the sum of the coefficients of the terms with the same exponent in each polynomial. Note that a highest resulting term may drop out.Analysis Objects Type Movement Namefirst operand Polynomial received leftPolysecond operand Polynomial received rightPolysum polynomial Polynomial returned sumPoly● operator* - friend overloaded arithmetic operator*. Returns a Polynomial object that is the product of the parameters. The product of two polynomials is obtained by multiplying the terms of the left operand by each term of the right operand and combining the results. Multiplying two terms results in a term that is the product of the coefficients and the sum of the exponents.Analysis Objects Type Movement Namefirst operand Polynomial received leftPolysecond operand Polynomial received rightPolyproduct polynomial Polynomial returned prodPoly● operator<< - friend overloaded operator function that writes Polynomial to an output stream in mathematical format with exponentiation represented by ^ and no spaces between the terms. For example, x^3-2x^2+2x+1. Negative coefficients are written as subtraction (unless it is the first term), non-constant terms with coefficient 1 or -1 do not show the coefficient, terms with power 1 do not show an exponent, and the constant term does not show x or an exponent. Analysis Typos fixed 09/28/2010 Page 2 of 4 D.HwangObjects Type Movement Nameoutput stream ostreamreceived, passed back, and returnedoutpolynomial object Polynomial received aPoly● operator>> - friend overloaded operator function that reads Polynomial values from an input stream without prompting in mathematical format with exponentiation represented by ^ and without spaces. For example, x^3-2x^2+2x+1. Negative coefficients are written as subtraction (unless it is the first term), non-constant terms with coefficient 1 or -1 do not show the coefficient, terms with power 1 do not show an exponent, and the constant term does not show x or an exponent. Assumes that the powers are in decreasing order. (I.e., you do not need to do error checking or sort the terms.) Analysis Objects Type Movement Nameinput stream istreamreceived, passed back, and returnedinpolynomial object Polynomial passed back aPolyNotes: Since both coefficients and exponents may be missing, you may want to consider using in.peek() to look ahead into the input stream or in.putback(ch), which will put a character back into the input stream. E.g., a character could be read and determined to be a numeric digit, then put back into the input stream to be read again as part of a double. Also, this operator should be able to skip any whitespace occurring before the input and not remove the whitespace occurring after the input. For the purposes of this project, you may assume that there will always be whitespace after a Polynomial input (one or more spaces, tabs, newlines, or the end of file).Assignment Write the implementation for this Polynomial class. Note that the function names for this class must be as specified above as well as the order of the parameters (though not necessarily the parameter names). The Polynomial class definition and friend operator function prototypes should be put in header file polynomial.h with suitable compilation guards. The implementations of the Polynomial class and friend operator functions should be put in source file polynomial.cpp. Both should use namespace Project3. Write an interactive test program in the style given in Section 3.3 of the textbook in file project3.cpp. In addition, the submission system will run a specific driver program to test your Polynomial class. The Polynomial class must be implemented using a vector. Projects that do not use a vector will be returned for resubmission with late penalty.You must submit a makefile named


View Full Document

UE CS 215 - CS 215 ­ Fundamentals of Programming II Project 3

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download CS 215 ­ Fundamentals of Programming II Project 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 215 ­ Fundamentals of Programming II Project 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 215 ­ Fundamentals of Programming II Project 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?