CSCI 240 - Assignment 8 - Spring 2007

Points: 100
Due: Monday, April  2, 3 pm


Overview

Write a program to analyze quadratic equations. It will find the roots of the equation (if any) and will also calculate and display the x- and y-coordinates of the vertex of the parabola represented by the equation and whether the curve is concave upwards or concave downwards.  It will then ask the user if another set of calculations should be performed.

A typical single run of the program should resemble the following:

Quadratic Equation Analyzer
Enter the a coeficient: 1
Enter the b coefficient: 2
Enter the c coefficient: -2
Using reference args:
The parabola opens upwards.
The coordinates of the vertex are x = xx.xxx and y = zz.zzz
The parabola has 2 roots at 
  x = nn.nnn  
  x = aa.aaa 
Another? (y/n) n

Recall that the general quadratic equation is: 
The formula for the roots of a quadratic equation is:
The x-coordinate of the vertex is at:
The y-coordinate of the vertex is at:

Recall also that a quadratic equation is in the shape of a parabola. The parabola opens upward if the coefficient of x-squared ("a" in the equations above) is positive and it opens downward if it is negative. The coefficient must be non-zero (if it is zero, the equation is of a straight line). The other constants (b and c) can be any real values.

The roots of the equation are the places where the parabola cuts the x-axis. If the parabola is entirely above the x-axis and opens upward or if it is below the x-axis and opens downward, it has no real roots. If it just touches the x-axis, it has one root with a multiplicity of 2. Otherwise, it cuts the axis at 2 points.

You can determine which of these cases holds for a given equation by checking the value of the discriminant (the quantity under the square root sign). If it is positive, there are two real roots; if it is 0 there is one root and if it is negative, there are no real roots.

Your program should prompt the user to enter "a", and if 0 is entered, display an error message and ask for a valid value. Do this repeatedly until a valid value is entered.

It should then prompt for and accept b and then c. Any real values are valid.

The program should then determine and display

The program should then ask if the user wishes to do another equation. Accept either "y" or "Y" as positive responses.

When your program starts it should display a title on the screen. All prompts should be clear and accurate. All calculated results should be presented with clear and accurate labels. Print results one item per line. Print real number results to 3 decimal places. Test your program for all possible cases before you conclude it is finished and correct. Use equations of parabolas whose roots, concavity, and vertex location you know.

Functions

You must implement this program in part by writing and using the following functions.  Some functions simply return a value.  Others pass back results by reference

double getA() - this function will prompt the user to enter the value of the a-coefficient.  It will check to see if it is 0.  If it is, it will issue an error message and prompt for a non-zero value.  It will not return until the user has entered a non-zero value; it will then return that non-zero value.

void getDiscr(double a, double b, double c, double& discr) - this function will calculate and pass back the value of the discriminant.  a, b, and c are the coefficients as entered by the user.

void getVertex(double a, double b, double c, double& x, double& y) will calculate and pass back the x and the y coordinate of the vertex using reference arguments.

void getRoots(double a, double b, double c, int& numRoots, double& root1, double& root2)  will calculate how many roots there are:

The calling program can then check the value of numRoots to decide what to display.

Notes

Once again, we suggest you develop this program incrementally. 

Documentation as usual.