CSCI 2421 homework 3

Program objectives

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).

Point value

This program is worth 15 points. The distribution of points will be as follows.



Global functions


Poly class


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.

  1. p1 + p2
  2. p1 * p2
  3. p1 (n), nZ


  1. 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[1].
  2. A number, nZ input on the command line in positional parameter argv[2] 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[2] is type char*, so it must be converted to type int by your program (a global function).

Class requirements

  1. Use a dynamic array to implement your polynomial.
  2. Define a constant member to evaluate a polynomial at a value n.
  3. Define a “setter” to set any coefficient requested.
  4. Define a “getter” to return any coefficient requested.
  5. Overload operators + and * for the polynomial class.
  6. Overload operator << for polynomial class.
  7. 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


  1. Greet the user.
  2. Instantiate p1 and p2.
  3. Read the text file and set the coefficients of p1 and p2.
  4. Perform the polynomial arithmetic per the problem specification and display the annotated results.
  5. Convert argv[2] to an int, evaluate p1 at this value, and display the annotated result.


  1. Use an appropriate annotation with all output.
  2. Make sure that main is short. It should basically be making top-level function calls.
  3. 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.
  4. You are not restricted to the polynomial members listed above; that is, you may define other members that you feel necessary.
  5. Be sure to use error checking where appropriate.