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

Please circle or color ONE! When calling a method and passing arguments to param

ID: 674074 • Letter: P

Question

Please circle or color ONE! When calling a method and passing arguments to parameters:

a. The number of arguments and parameters doesn’t have to match; the names of the arguments and parameters have to match, their order doesn’t have to be the same; their data types don’t have to match; the return data type doesn’t need to match the datatype of the variable the return is assigned to in the call.

b. The number of arguments and parameters has to match; the names of the arguments and parameters have to match, their order has to be the same; their data types don’t have to match; the return data type needs to match the datatype of the variable the return is assigned to in the call.

c. The number of arguments and parameters has to match; the names of the arguments and parameters don’t have to match, their order has to be the same; their data types have to match; the return data type needs to match the datatype of the variable the return is assigned to in the call.

d. The number of arguments and parameters has to match; the names of the arguments and parameters don’t have to be the same, their order doesn’t have to be the same; their data types has to be the same; the return data type doesn’t need to match the datatype of the variable the return is assigned to in the call.

Explanation / Answer

Answer:

c. The number of arguments and parameters has to match; the names of the arguments and parameters don’t have to match, their order has to be the same; their data types have to match; the return data type needs to match the datatype of the variable the return is assigned to in the call.

Demo for calling a method and passing arguments to parameters:

For example,

Program code:

#include "stdafx.h"

#include <iostream>

using namespace std;

double addNumbers(double a, double b, double c)

{

     double res = a+b+c;

     return res;

}

int main()

{

     double x =10, y =20, z=30;

     double result = addNumbers(x, y, z);

     cout<<"The resultant value is: "<<result<<endl;

     system("pause");

     return 0;

}

Sample output:

The resultant value is: 60

Press any key to continue . . .

Program code:

#include "stdafx.h"

#include <iostream>

using namespace std;

int addNumbers(double a, double b, double c)

{

     double res = a+b+c;

     return res;

}

int main()

{

     double x =10.5, y =20.12, z=30.25;

     double result = addNumbers(x, y, z);

     cout<<"The resultant value is: "<<result<<endl;

     system("pause");

     return 0;

}

Sample Output:

The resultant value is: 60

Press any key to continue . . .

Program code:

#include "stdafx.h"

#include <iostream>

using namespace std;

double addNumbers(double a, double b, double c)

{

     double res = a+b+c;

     return res;

}

int main()

{

     double x =10.5, y =20.12, z=30.25;

     double result = addNumbers(x, y, z);

     cout<<"The resultant value is: "<<result<<endl;

     system("pause");

     return 0;

}

Sample output:

The resultant value is: 60.87

Press any key to continue . . .