Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prompt the user for 3 numbers a, b, and c as part of the quadratic equation ax 2 + bx + c = 0. Use

Prompt the user for 3 numbers a, b, and c as part of the quadratic equation

ax2 + bx + c = 0. Use the quadratic equation formula from the notes to determine if: 1) the equation is not quadratic 2) there are no real roots, 3) one real root, 4) or two real roots. Use the file proj1_P4.cpp which was emailed to you. Do not change any source code in the main code block. You are to implement the following method:

int SolveQuadraticEq(double a, double b, double c, double &r1, double &r2)

If a = 0 then ax2 + bx + c = 0 becomes bx + c = 0 and we are no longer solving a quadratic equation. Also remember the square root of a negative number is undefined in a computer. Use the discriminant to determine if there are no real roots, one root, or two roots. Output from your program might look like:

Enter a:

2.0

Enter b:

5.0

Enter c:

-3.0

There are two real roots and they are -3.0 and 0.5

Enter a:

0.0

Enter b:

5.0

Enter c:

-3.0

There are no real roots

Enter a:

1.0

Enter b:

-3.0

Enter c:

0.0

There are two real roots and they are 3.0 and 0.0

(Here is the Code Needed to complete the Problem):

#include  #include  using namespace std; // Student should add a function prototype block here //////////////////////////////////////////////////////////////////////// // // int returm value: -1 - not a quadratice equation // 0 - no real roots // 1 - one real root // 2 - two real roots // //////////////////////////////////////////////////////////////////////// int SolveQuadraticEq(double a, double b, double c, double &r1, double &r2); //////////////////////////////////////////////////////////////////////////// // // Students should not change source in main code block // ///////////////////////////////////////////////////////////////////////////// int main() { double a, b, c, root1, root2; cout << "Enter a " << endl; cin >> a; cout << "Enter b " << endl; cin >> b; cout << "Enter c " << endl; cin >> c; int status = SolveQuadraticEq(a, b, c, root1, root2); switch (status) { case -1: { cout << "This is not a quadratic " << endl; } case 0: { cout << "This are no real solutions " << endl; } break; case 1: { cout << "The one real solution is " << root1 << endl; } break; case 2: { cout << "There are two real solutions: " << root1 << " and " << root2 << endl; } } return 0; } //////////////////////////////////////////////////////////////////////////// // // Students are to add a method defintion for SolveQuadraticEq below this comment block // ////////////////////////////////////////////////////////////////////////////////

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions