COSC 2415 - Data Structures and
ITSE 2445 Data Structures

Bob Comer, Professor of Computer Studies


Program 1 - Quadratic Expressions

Be sure to read through Chapter 4 of the textbook before starting this assignment.

The objective is to construct a comprehensive class that can be used for many different applications in client programs. Your project should be divided into separate files - a class definition file, a class implementation file, and the client (driver) program. Be sure that your driver includes code to test all your class functions.

A quadratic expression has the form

ax2 + bx + c

where x is a variable that can take on different numeric values and a, b and c are constants (fixed numeric values). Create a class to store a quadratic expression. Note that a quadratic expression is defined by 3 floating-point values - the 3 coefficients a, b, and c.

Your class should include:

You may want to thoroughly test your class at this point before continuing the assignment.

A real root of a quadratic expression is any double valuex such that ax2 + bx + c = 0. A quadratic expression can have 0, 1, 2, or an infinite number of roots. The following cases define the real roots for a quadratic expression. Note that these cases cover all possibilities and do not overlap (they are mutually exclusive).

  1. If a, b and c are all zero, then every value of x is a real root.
  2. If a and b are zero and c is non-zero, then there are no real roots.
  3. If a is zero and b is non-zero, then the only real root is x = -c/b.
  4. If a is non-zero and b2 < 4ac, then there are no real roots.
  5. If a is non-zero and b2 = 4ac, then there is one real root x = -b/2a.
  6. If a is non-zero and b2 > 4ac, then there are two real roots:
           -b - sqrt( b2 - 4ac )
    x = ________________
                    2a

           -b + sqrt( b2 - 4ac )
    x = ________________
                    2a