Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1_. 2_ 3. [8 pointsl The function below is intended to find the roots of a quadr

ID: 3710831 • Letter: 1

Question

1_.

2_


3. [8 pointsl The function below is intended to find the roots of a quadratic equation and pass them back throngh ri and r2. It contains two (2) logical errors and six (6) syntax errors. Indicate the location of each crror in the code with a letter, a -h, and on the corresponding line below explain the crror and/or the correction. void quadraticRoots (double a, double b, double c, double rl, doublek r2) f int numRoots0: ir (a) if (b 0) f ri-, c/b; r2 rl; numRoots 1 } Else { // a !?0 double discrim bb-4.a*c if (discrim )l/ real roots rl(bsqrt (diserim)/(2.a) r2 _ ( b, sqrt, ( discrim))/(2*a); numRoots 2 l clse (diserim0) I numRoots rl -.-b/(2a); return numRoots

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote