The following function is intended to calculate the equivale

The following function is intended to calculate the equivalent resistance of two parallel resistors, but it contains several mistakes. Identify five errors in the function, specifying whether each error is a problem with the functions syntax or semantics./** * Calculate the equivalent resistance of two parallel resistors. * * r1 the resistance of one resistor (Ohms] * 0 r2 the resistance of the other resistor [Ohms] * * returns the equivalent resistance [Ohms] */double req (double r1, r2) {If (r1 = = r2) {double numerator = r1 * r2 return numerator/r1 + r2;} return r1;}

Solution

double req(double r1, r2){ // ERROR1 : Syntax error => missing data type for r2
  
   // ERROR 2: Syntax error: IF is not a valid keyword. it should be \'if\'
   // ERROR 5: Symentic, if condition does not require, formula is same for any
                   // value of registor
   IF(r1==r2){
       double numerator = r1+r2;
       return numerator/r1+r2; // ERROR 3: Symantic error: it shpuld be
                               // numerator/(r1*r2)
   }

   return r1;// ERROR 4: Symantic error, it should be (r1+r2)/(r1*r2)
}

 The following function is intended to calculate the equivalent resistance of two parallel resistors, but it contains several mistakes. Identify five errors in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site