1_. 2_ 3. [8 pointsl The function below is intended to find the roots of a quadr
ID: 3710831 • Letter: 1
Question
1_.
2_
Explanation / Answer
int quadraticRoots(double a, double b, double c, double& r1, double r2) {
//a - return type is int
// b - r1 is reference wrongly, with the given value in question you can't get its value back in caller
int numRoots = 0;
if (a == 0) {
if (b != 0) {
// c - if b is 0, you can't really divide
r1 = -c/b;
r2 = r1;
numRoots = 1;
} else { // a!= 0
// d - E should be small
r1 = -b;
// e- incorrect assigning r1
double discrim = b*b -4*a*c;
// f - missing semicolon
if (discrim > 0) { // real roots
r1 = (-b + sqrt(discrim))/(2*a);
r2 = (-b - sqrt(discrim))/(2*a);
numRoots = 2;
} else if(discrim == 0) {
// g - missing if
numRoots = 1;
r1 = -b/(2*a);
// h - missing multiplication
}
}
}
return numRoots;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.