Consider the quadratic expression x2 − 4x + 3 Describing where this quadratic is negative involves describing a set of numbers that are simultaneously greater than the smaller root (+1) and less than the larger root (+3). Write a C++ Boolean expression that is true when the value of this quadratic is negative.
PROGRAM CODE:
//Header section
#include <iostream>
#include <cmath>
using namespace std;
//Program starts a main method
int main()
{
// Declare the coefficients of the quadratic expression
int a = 1; // coefficient of x^2
int b = -4; // coefficient of x
int c = 3; // constant term
// Calculate the discriminant to determine the nature of the roots
int discriminant = b * b - 4 * a * c;
// Check if the discriminant is greater than zero (real and distinct roots)
if (discriminant > 0) {
// Calculate the roots of the quadratic equation
float root1 = (-b + sqrt(discriminant)) / (2 * a);
float root2 = (-b - sqrt(discriminant)) / (2 * a);
// Check if the expression is negative in the interval (root1, root2)
if (root1 < root2) {
// Check if a number falls within the range (root1, root2)
float numberToCheck = 2; // Replace with the desired number
// Check if the number falls within the range
if (numberToCheck > root1 && numberToCheck < root2) {
cout << "The quadratic expression is negative when x is between "
<< root1 << " and " << root2 << endl;
return true;
}
}
}
cout << "The quadratic expression is not negative." << endl;
return false;
}
OUTPUT OF THE PROGRAM CODE:
The quadratic expression is not negative.