Question. How many boolean expressions are specified? int main() { double a, b,
ID: 3736267 • Letter: Q
Question
Question. How many boolean expressions are specified?
int main()
{ double a, b, c, disc, root1, root2;
cout << "This program calculates the roots of a ";
cout << " quadratic equation of the form ";
cout << " 2 ";
cout << " ax + bx + c = 0 ";
cout << "Please enter values for a, b, and c: ";
cin >> a >> b >> c;
if ( a == 0.0 && b == 0.0)
cout << "The equation is degenerate and has no roots. ";
else if (a == 0.0)
cout << "The equation has the single root x = "
<< -c/b << endl;
else
{
disc = pow(b,2.0) - 4 * a * c; // calculate discriminant
if (disc > 0.0)
{
disc = sqrt(disc);
root1 = (-b + disc) / (2 * a);
root2 = (-b - disc) / (2 * a);
cout << "The two real roots are "
<< root1 << " and " << root2 << endl;
}
else if (disc < 0.0)
cout << "Both roots are imaginary. ";
else
cout << "Both roots are equal to " << -b / (2 * a) << endl;
}
return 0; }
Explanation / Answer
1) a == 0.0
Explanation: The above is boolean expression because it compares a with 0, and this expression gives us true or false
2) b == 0.0
Explanation: The above is boolean expression because it compares b with 0, and this expression gives us true or false
3) a == 0.0
Explanation: The above is boolean expression because it compares a with 0, and this expression gives us true or false
4)disc > 0.0
Explanation: The above is boolean expression because it compares disc > 0, and this expression gives us true or false
5)disc < 0.0
Explanation: The above is boolean expression because it compares disc < 0, and this expression gives us true or false
So there are Total 5 boolean expression. Thanks let me know if there is any concern.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.