Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview For this program, continue the parabola by adding code that will determine (and display) the concavity of the parabola, and determine if the parabola

Overview

For this program, continue the parabola by adding code that will determine (and display) the concavity of the parabola, and determine 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 added calculations.

Basic Program Logic C++

As with program 2, the user will still be prompted to enter the a, b, and c-coefficients. However, 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). Any value is allowed for the b and c-coefficients.

The program should still calculate and display the coordinates for the vertex.

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.

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:

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 with program 2, all of the values should be displayed in a neat tabular format with the decimal point of all of the numeric values lined up and exactly 3 digits after the decimal point.

Program Requirements

sqrt( value )

  1. 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:

  2. All of the values in the table should be displayed with exactly 3 digits after the decimal point, including zeroes.

I have half of the program done but I need help/confirmation for the other requirements.

#include

#include

using namespace std;

int main()

{

// Step one: reate the variables

double acoef, bcoef, ccoef, xvertex, yvertex;

// Step two: get values into the variables

cout

cin >> acoef;

cout

cin >> bcoef;

cout

cin >> ccoef;

// Calculate x cooridnates of the vertex

xvertex = -bcoef / (2 * acoef);

// Calculate y coordinates of the vertex

yvertex = (acoef * xvertex * xvertex)

+ (bcoef * xvertex) + ccoef;

/ew line

cout

cout

cout

cout

// Display the results

cout

cout

cout

cout

cout

// display the results

cout

cout

cout

cout

return 0

}

Sample Output:

image text in transcribed

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 b Coefficient c Coefficient -1.000 2.000 -1.000 Vertex X Coordinate Y Coordinate 1.000 9.000 The parabola opens DOWNWARD The parabola has ONE root Root 1- X Coordinate 1.000

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions