Here is a function declaration float ratiofloat x float y An

Here is a function declaration: float ratio(float x, float y); And here are some variables: float a = 6.23, b = 1.6, r; float d = {3.14, 1.41}; Which of the following is an INVALID way to call the function ratio? Explain your answer r = ratio(a, b); r = ratio(d[O], d[1]); r = ratio(a, d); r = ratio(a, d[1]); Here are some variables: int a = 6, b = 4, r; float d = {3.14, 1.41}; and here is a function call: d[0] = fraction(a, b); Which ONE of the following functions could reasonably be called by the function call given above? Explain your answer float fraction(int parts[2]); float fraction(numerator, denominator); float fraction(int numerator, int denominator);

Solution

(11)

   Given function declaration:
  
   float ratio(float x, float y);
  
   Input parameters: Two separate float type values
  
   Return Value: float type value
  
  
   Given Options:
  
  
   (a) r = ratio(a,b);
      
       a, b are declared as float type values and variable r is also declared as float type variable.
      
       This function call satisfies the signature of method ratio.
      
       Hence this is VALID.
  
  
   (b) r = ratio(d[0], d[1]);
      
       d is an array of float type type with 2 elements at indices 0, 1.
      
       d[0], d[1] are two float type values of array d and variable r is also declared as float type variable.
      
       This function call satisfies the signature of method ratio.
      
      Hence this is VALID.
  
  
  
   (c) r = ratio(a, d);
      
       d is an array of float type with 2 elements at indices 0, 1.
      
       a is a float variable but Variable d is holding an array of elements rather than single value
      
       Function ratio accepts two single float type variables but not array.
      
       This function call doesn\'t satisfies the signature of method ratio.
      
      Hence this is INVALID.
  
  
  
   (d) r = ratio(a, d[1]);
      
       d is an array of float type with 2 elements at indices 0, 1.
      
       a is a float variable and d[1] is a single float type value of array d at index 1.
      
       Function ratio accepts two single float type variables and returns a single float type variable.
      
       This function call satisfies the signature of method ratio.
      
      Hence this is VALID.
  
  
_________________________________________________________________________________________________________________________________________

(12)

   Given function call:

   d[0] = fraction(a, b);
  
   Variable d is an array of float type.
  
   Variables a, b are of two int types.
  
   The function call that satisfies the given call should be able to:
      
       (i) Two Input parameters of type int.
       (ii)   Return value of type float.
      
       float fraction(float, float);
      
   Given options:  
      
   (a) float fraction(int parts[2]);
  
       This function signature accepts a single int type value and returns a float type value.
      
       Hence this function signature is Not Correct.
      
  
   (b)   float fraction(numerator, denominator);
  
       Data types are missing in the function signature.
      
       Hence this function signature is Not Correct.
      
      
   (c) float fraction(int numerator, int denominator);
  
       This function signature accepts a two int type values and returns a single float type value.
      
       Function signature matches with function call.
      
       Hence this function signature is Correct.

 Here is a function declaration: float ratio(float x, float y); And here are some variables: float a = 6.23, b = 1.6, r; float d = {3.14, 1.41}; Which of the fo
 Here is a function declaration: float ratio(float x, float y); And here are some variables: float a = 6.23, b = 1.6, r; float d = {3.14, 1.41}; Which of the fo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site