### Need help with

This is a project I'm working on and i am totally lost with functions, I do not even know where to go or if im doing any of this right. Any hints towards what I need to do would be very helpful. Thanks

Purpose: The purpose of this program is to create a quadratic
equation analyzer that will calculate the coordinates
of the vertex, the concavity, and the root(s) of a
parabola. The user supplies the 3 coefficients that are
needed for the calculations.

It should be displaying something similar to this:

Run 1:

Enter the a coefficient (non-zero value): 1
Enter the b coefficient: 4
Enter the c coefficient: -5

*******************************************
*******************************************
a Coefficient 1.000
b Coefficient 4.000
c Coefficient -5.000
-------------------------------------------
X Coordinate -2.000
Y Coordinate -9.000
-------------------------------------------
The parabola opens UPWARD
-------------------------------------------
Root 1 X Coordinate 1.000
Root 2 X Coordinate -5.000

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169`` ``````#include #include #include using namespace std; //********************************************************************* //* //* Function Prototypes //* //********************************************************************* double getA (); double calcXvertex ( double, double ); double calcYvertex ( double, double, double ); void printConcavity ( double ); double calcDiscriminant ( double, double, double ); void printRoots ( double, double, double ); int main() { //********************************************************************* //* //* Variable Dictionary //* //* aCoeff, bCoeff, cCoeff - used to hold the coefficients //* //* xVertex - used to hold the X-coordinate of the vertex //* //* yVertex - used to hold the Y-coordinate of the vertex //* //********************************************************************* double aCoeff, bCoeff, cCoeff; double xVertex, yVertex; //Setup the formatting cout << fixed << setprecision(3); //Get the A, B, and C coefficients from the user cout << "Enter the a coefficient (non -zero value:\n"; cin >> aCoeff; while (aCoeff >0) { cout << "Error: The a-value MUST be non-zero. Try Again:"; cin >> aCoeff; } cout << "Enter the b coefficient: "; cin >> bCoeff; cout << "Enter the c coefficient: "; cin >> cCoeff; //Calculate the X and Y coordinates for the vertex of the parabola xVertex = -bCoeff/(2 * aCoeff); yVertex = (aCoeff * xVertex^2) + (bCoeff * xVertex) + cCoeff; //Display the coefficients and vertices cout << endl << "*******************************************" << endl << " Quadratic Equation Analyzer" << endl << "*******************************************" << endl << "a Coefficient" << setw(30) << aCoeff << endl << "b Coefficient" << setw(30) << bCoeff << endl << "c Coefficient" << setw(30) << cCoeff << endl << "-------------------------------------------" << endl << "X Coordinate" << setw(31) << xVertex << endl << "Y Coordinate" << setw(31) << yVertex << endl << "-------------------------------------------"; //Display the concavity of the parabola printConcavity( aCoeff ); //Display the roots cout << endl << "-------------------------------------------"; printRoots( aCoeff, bCoeff, cCoeff ); cout << endl << endl; return 0; } //***** Functions are coded below main() ***** double getA() { cout << "Enter the a coefficient (non -zero value:\n"; cin >> aCoeff; while (aCoeff >0) { cout << "Error: The a-value MUST be non-zero. Try Again:"; cin >> aCoeff; } return aCoeff; } double calcXvertex ( double, double ); { xVertex = -bCoeff / ( 2 * aCoeff); return xVertex; } double calcYvertex ( double, double, double ); { yVertex = ( aCoeff * xVertex^2 ) + ( bCoeff * xVertex ) + cCoeff; return yVertex; } void printConcavity ( double ); { if ( aCoeff > 0 ) { cout << "Parabola opens UPWARD." << endl; } else { cout << "Parabola opens DOWNWARD." << endl; } return 0; } double calcDiscriminant ( double, double, double ); { double discriminant; discriminant = bCoeff^2 - 4 * aCoeff * cCoeff; return discriminant; } void printRoots ( double, double, double ); { if ( calcDiscriminant > 0 ) { cout << "There are two real roots."; } if else ( calcDiscriminant == 0 ) { cout << "It has one root with a multiplicity of 2."; } else { cout << "There are no real roots"; } return 0; } ``````
Topic archived. No new replies allowed.