Question
***IN C++ LANGUAGE*** Overview For this program, write a program that will display information about a parabola. The program will determine (and display) the concavity
***IN C++ LANGUAGE*** Overview
For this program, write a program that will display information about a parabola. The program will determine (and display) the concavity of the parabola, and if the parabola has real roots and what they are if they exist.
The program will also do a little bit of error-checking along with the calculations.
Basic Program Logic
For this program, ask the user for the a-coefficient of the parabola. This is an integer value and must be placed into an integer variable. The a-coefficient needs to checked for validity. If the value the user enters is 0, display a message that the a-coefficient must be non-zero and ask the user to re-enter the value. This only needs to be done one time (i.e. we'll assume the user "gets it right" on the second try).
Ask the user for the b and c-coefficients. The two values should also be placed in integer variables. Any value is allowed for the b and c-coefficients.
The output for the program should be displayed in a tabular format. This is a place where part of the table can be displayed. Display a title for the table and the three coefficients that have been entered by the user. Note: the display of the entire table can be saved until the end of the program if desired. It is simply a suggestion to display it in parts.
Use the a-coefficient to determine the concavity of the parabola. If the a-coefficient is positive, then the parabola opens upward. If it's negative, then the parabola opens downward. Display the concavity (the direction that the parabola opens) if the table is being displayed in parts.
Now determine the roots of the parabola. The roots are the places where the parabola intersects the x-axis. If the parabola is entirely above or below the x-axis, there are no real roots. If it just touches the x-axis, it has one root with a multiplicity of 2. Otherwise, it intersects the x-axis at 2 points.
To determine which case holds true, calculate the discriminant and check its value. If the discriminant is positive, there are two real roots. If it's 0, there is one real root with multiplicity 2 (i.e. either root formula from below can be used to calculate the root since the result will be the same with either formula). If it's negative, there are no real roots.
Use the following equations to calculate the discriminant and roots. All the values should be float/double values:
discriminant = b-coefficient * b-coefficient - 4 * a-coefficient * c-coefficient root 1 = ( -b-coefficient + sqrt( discriminant )) / ( 2 * a-coefficient ) root 2 = ( -b-coefficient - sqrt( discriminant )) / ( 2 * a-coefficient )
Note: see Program Requirement #2 for information about sqrt.
For the roots, display the number of roots that the parabola has and, if they exist, the values.
As mentioned earlier, all the values should be displayed in a neat tabular format with the decimal point of all the numeric values lined up and exactly 3 digits after the decimal points.
Program Requirements
-
sqrt is the name of a function that calculates the square root of a number. It is part of the cmath library. Make sure to add #include
at the top of the code so that the sqrt function can be used. To calculate the square root of a value: -
All the values in the table should be displayed with exactly 3 digits after the decimal point, including zeroes.
-
Use type int for the values read in from the user. Use meaningful variable names
Sample Output:
A few runs of the program might resemble the following:
Run 1:
Enter the a coefficient (non-zero value): 1 Enter the b coefficient: 4 Enter the c coefficient: -5 ------------------------------- Quadratic Equation Analyzer ------------------------------- a Coefficient 1 b Coefficient 4 c Coefficient -5 ------------------------------- The parabola opens UPWARD ------------------------------- The parabola has TWO roots Root 1 1.000 Root 2 -5.000
Run 2:
Enter the a coefficient (non-zero value): 0 Error: the a-coefficient MUST be non-zero. Try again: -1 Enter the b coefficient: 2 Enter the c coefficient: -1 ------------------------------- Quadratic Equation Analyzer ------------------------------- a Coefficient -1 b Coefficient 2 c Coefficient -1 ------------------------------- The parabola opens DOWNWARD ------------------------------- The parabola has ONE root Root 1 1.000
Run 3:
Enter the a coefficient (non-zero value): 12 Enter the b coefficient: 2 Enter the c coefficient: 3 ------------------------------- Quadratic Equation Analyzer ------------------------------- a Coefficient 12 b Coefficient 2 c Coefficient 3 ------------------------------- The parabola opens UPWARD ------------------------------- The parabola has NO roots
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started