Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, design and use a class that can be used to represent a parabola. The Parabola class Data Members The class contains three

For this assignment, design and use a class that can be used to represent a parabola.

The Parabola class

Data Members

The class contains three data members:

a double that holds the value of the a-coefficient of the parabola

a double that holds the value of the b-coefficient of the parabola

a double that holds the value of the c-coefficient of the parabola

Constructor

The constructor for the class is used to create a Parabola object. 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-coefficients to initialize the respective data members.

Methods

The following methods are required for the Parabola class.

double calcDiscrim()

This method calculates and returns the value of the discriminant. It takes no arguments and returns a double: the calculated discriminant. The discrimant is calculated as follows:

discriminant = b-coefficient2 - 4 * a-coefficient * c-coefficient 

int calcRoots( double &root1, double &root2 )

This method calculates and passes back the roots for the parabola, if they exist, and returns the number of roots. 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: 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 by calling the calcDiscrim() method and check its value. If the discriminat:

is positive, there are two real roots and those values should be calculated using both of the formulas from below and passed back via the two reference arguments. The method should also return the value 2 to reflect that there are two roots.

is 0, there is one real root with multiplicity 2. Use either one of the root formulas from below to calculate the root and then pass the value back via the first root argument. Return the value 1 to indicate there is only one root.

is negative, there are no real roots and the only thing the method should do is return 0.

Use the following equations to calculate the roots:

root 1 = ( -b-coefficient + sqrt( discriminant )) / ( 2 * a-coefficient ) root 2 = ( -b-coefficient - sqrt( discriminant )) / ( 2 * a-coefficient ) 

NOTE: make sure to add #include to the top of the code so that the sqrt() function can be used in the code.

double calcX()

This method calculates and returns the x-coordinate of the vertex of the parabola. It takes no arguments and returns a double: the calculated x-coordinate.

The x-coordinate of the vertex is calculated as follows:

x-Coordinate = - b-coefficient / ( 2 * a-coefficient) 

double calcY()

This method calculates and returns the y-coordinate of the vertex of the parabola. It takes no arguments and returns a double: the calculated y-coordinate.

The y-coordinate of the vertex is calculated as follows:

y-Coordinate = ( a-coefficient * x-Coordinate2 ) + ( b-coefficient * y-Coordinate ) + c-coefficient 

Call the calcX() method to get the value of the x-coordinate and then use it to calculate the value of the y-coordinate.

void printEquation()

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:

a-coefficient x^2 + b-coefficient x + c-coefficient 

The coefficients should have exactly 1 digit after the decimal point. So if an object has an a-coefficient value of 1, b-coefficient value of 4, and c-coefficient value of -5, the equation will display as:

1.0x^2 + 4.0x + -5.0 

void printVertex()

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, respectively. Those values should then be displayed in the following manner:

 Vertex Coordinates: (X-Coordinate, Y-Coordinate) 

The coordinates should have exactly 3 digits after the decimal point. For example:

 Vertex Coordinates: (-2.000, -9.000) 

void printRoots()

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 the values of those roots (if they exist). Depending upon how many roots exist, the method should display:

 There are NO real roots 

or

 There is one real root with X-Coordinate root_1_value 

or

 There are two real roots with X-Coordinates root_1_value and root_2_value 

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.

void printConcavity()

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:

 The parabola opens UPWARD 

should be displayed. If it's negative, then the parabola opens downward and:

 The parabola opens DOWNWARD 

should be displayed.

void print()

This method displays everything related to the parabola. It takes no arguments and returns nothing.

So if an object has an a-coefficient value of 1, b-coefficient value of 4, and c-coefficient value of -5, this will display:

1.0x^2 + 4.0x + -5.0 Vertex Coordinates: (-2.000, -9.000) The parabola opens UPWARD There are two real roots with X-Coordinates 1.000 and -5.000 

call the printEquation(), printVertex(), printConcavity(), and printRoots() methods to display the various values.

main()

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.

Programming Notes

Each method must have a documentation box like a function.

Hand in a copy of your source code using Blackboard.

Output

*** The first parabola *** 1.0x^2 + 4.0x + -5.0 Vertex Coordinates: (-2.000, -9.000) The parabola opens UPWARD There are two real roots with X-Coordinates 1.000 and -5.000 *** The second parabola *** 1.0x^2 + 0.0x + 25.0 Vertex Coordinates: (-0.000, 25.000) The parabola opens UPWARD There are NO real roots *** The third parabola *** -1.0x^2 + 2.0x + -1.0 The parabola opens DOWNWARD *** The fourth parabola *** There are two real roots with X-Coordinates -0.590 and 0.424 *** The fifth parabola *** 12.0x^2 + 2.0x + 3.0 Vertex Coordinates: (-0.083, 2.917) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

=+ 6. A Case Study in this chapter concludes that if

Answered: 1 week ago