- CSCI 2421 homework 3
CSCI 2421 homework 3
The objectives of this assignment are as follows.
An ability to analyze a problem, and identify and define the computing requirements appropriate to its solution (ABET b).
This program is worth 15 points. The distribution of points will be as follows.
Program style (see below)
Correct output with annotation
A polynomial is a function of the following form:
d p(n) =∑aini , where d is an integer and the ai are the coefficients with ad ≠ 0.
i=0 p(n) is said to be a polynomial in n of degree d.
Create a class named polynomial that uses a dynamic array to perform the following arithmetic for polynomials, p1 and p2.
- p1 + p2
- p1 * p2
- p1 (n), n ∈ Z
- A text file consisting of two rows of space-delimited integers. Each row represents the coefficients, ai for a polynomial p. The first number on each row represents a0 and the last number ad. Notice that any ai (except ad) may be 0. No coefficient will be missing, even if it is 0. The name of the text file will be available in positional parameter, argv.
- A number, n ∈ Z input on the command line in positional parameter argv that is used to evaluate polynomial p1. For example, if p1 = (1, 0, 3, 0, 0) and n=2, then p1(2) = 28. Notice that argv is type char*, so it must be converted to type int by your program (a global function).
- Use a dynamic array to implement your polynomial.
- Define a constant member to evaluate a polynomial at a value n.
- Define a “setter” to set any coefficient requested.
- Define a “getter” to return any coefficient requested.
- Overload operators + and * for the polynomial class.
- Overload operator << for polynomial class.
- Operator << should display the polynomial as an n-tuple in the order highest term to lowest term. For example,
(3, -2, 0, 0, 7) ≡ 3x4 – 2x3 + 7
- Greet the user.
- Instantiate p1 and p2.
- Read the text file and set the coefficients of p1 and p2.
- Perform the polynomial arithmetic per the problem specification and display the annotated results.
- Convert argv to an int, evaluate p1 at this value, and display the annotated result.
- Use an appropriate annotation with all output.
- Make sure that main is short. It should basically be making top-level function calls.
- Use good program style that includes, but is not limited to, header comments, pre and post conditions, macro guards, whitespace and indentation, self-documenting names, symbolic constants where appropriate (use all caps for the name of each symbolics), separation of interface and implementation, correctly submitted program file (tar archive), and a greeting to start the program.
- You are not restricted to the polynomial members listed above; that is, you may define other members that you feel necessary.
- Be sure to use error checking where appropriate.