For this assignment, design a class that can be used to represent a parabola. Us
ID: 3533534 • Letter: F
Question
For this assignment, design a class that can be used to represent a parabola.
Use the following class definition:
The data members for the class are:
aCoeff this holds the value of the a-coefficient of the parabola
bCoeff this holds the value of the b-coefficient of the parabola
cCoeff this holds the value of the c-coefficient of the parabola
The constructor for the class should initialize the data members using the passed in arguments. It takes 3 arguments: a double that holds the initial value for the a-coefficient, a double that holds the initial value for the b-coefficient, and a double that holds the initial value for the c-coefficient. If the passed-in value for the a-coefficient is 0, initialize the a-coefficient data member to a value of 1. If the passed-in value for the a-coefficient is non-zero, use it to initialize the value of the a-coefficient data member. Use the passed-in values for the b and c-coefficient to initialize the respective data members.
This method calculates and returns the value of the discriminant. It takes no arguments and returns a double. The discrimant is calculated as follows:
This method calculates and passes back the roots for the parabola, if they exist. It takes two arguments: a reference to a double to pass back the first root and a reference to a double to pass back the second root. It returns an integer that represents the number of roots
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 cuts the x-axis at 2 points.
To determine which case holds true, calculate the discriminant and check its value. If the discriminat:
Use the following equations to calculate the roots:
This method calculates and returns the x-coordinate of the vertex of the parabola. It takes no arguments and returns a double.
The x-coordinate of the vertex is calculated as follows:
This method calculates and returns the y-coordinate of the vertex of the parabola. It takes no arguments and returns a double.
The y-coordinate of the vertex is calculated as follows:
Call the calcX method to get the value of the x-coordinate and then use it to calculate the value of the y-coordinate.
This method displays the parabola in the form of a quadratic equation. It takes no arguments and returns nothing.
The equation should be displayed in the following manner:
The coefficients should have exactly 1 digit after the decimal point. So if an object has an aCoeff value of 1, bCoeff value of 4, and cCoeff value of -5, the equation will display as:
This method displays the x and y-coordinates of the vertex of the parabola. It takes no arguments and returns nothing.
This method should call the calcX and calcY methods to get the x and y-coordinates of the vertex. Those values should then be displayed in the following manner:
The coordinates should have exactly 3 digits after the decimal point. For example:
This method displays the roots of the parabola (if they exist). It takes no arguments and returns nothing.
This method should call the calcRoots method to get the number of roots that the equation has and what the values of those roots (if they exist). Depending upon how many roots exist, the method should display:
or
or
where root_1_value and root_2_value are replaced by the calculated values (ie. the value(s) that are passed back by the calcRoots method). The coordinates should have exactly 3 digits after the decimal point.
This method displays the direction that the parabola opens. It takes no arguments and returns nothing.
The a-coefficient is used to determine if the parabola opens upward or downward. If the a-coefficient is positive, then the parabola opens upward and:
should be displayed. If it's negative, then the parabola opens downward and:
should be displayed.
This method displays everything related to the parabola. It takes no arguments and returns nothing.
So if an object has an aCoeff value of 1, bCoeff value of 4, and cCoeff value of -5, this will display:
call the printEquation, printVertex, printConcavity, and printRoots methods to display the various values.
In main(), create 5 Parabola objects. They should contain the values:
The first parabola should have an a-coefficient of 1, b-coefficient of 4, and a c-coefficient of -5
The second parabola should have an a-coefficient of 0, b-coefficient of 0, and a c-coefficient of 25
The third parabola should have an a-coefficient of -1, b-coefficient of 2, and a c-coefficient of -1
The fourth parabola should have an a-coefficient of -12, b-coefficient of -2, and a c-coefficient of 3
The fifth parabola should have an a-coefficient of 12, b-coefficient of 2, and a c-coefficient of 3
The rest of main() will include using the various print methods on each of the 5 Parabola objects. Display a label similar to "The first parabola" before anything is outputted for each of the objects.
For the first parabola, display all of the information for the parabola.
For the second parabola, display all of the information for the parabola.
For the third parabola, display the equation and the concavity.
For the fourth parabola, display only the roots.
For the fifth parabola, display the equation and the vertex.
Each method must have a documentation box like a function.
Hand in a copy of your source code using Blackboard.
Explanation / Answer
#include #include #include using namespace std; class Parabola{ private: double Coeff, aCoeff, bCoeff, cCoeff; public: Parabola(double a, double b, double c){ if(a==0) Coeff = 1; else aCoeff = a; bCoeff = b; cCoeff = c; } double calcDiscrim(){ return( (bCoeff * bCoeff) - (4 * aCoeff * cCoeff) ); } double calcRoots(double &root1, double &root2){ if(calcDiscrim()==0){ root1 = -bCoeff / (2 * aCoeff); return 1; } if(calcDiscrim()>0){ root1 = (-bCoeff + sqrt(calcDiscrim())) / (2 * aCoeff); root2 = (-bCoeff + sqrt(calcDiscrim())) / (2 * aCoeff); return 2; } if(calcDiscrim()Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.