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

1. Match the signature on the left with the correct method call on the right. If

ID: 671103 • Letter: 1

Question

1. Match the signature on the left with the correct method call on the right. If there are signatures that do not match any method, say so.

Assume the following declarations have been made:

String stringResult;

int integralResult;

double doubleResult;

int calculate()

doubleResult = calculate(3, 9.5)

int calculate(int a, double b)

doubleResult = calculate(2.7, 3.9)

void calculate (int a, int b, int c)

calculate(2, 4, 7)

double calculate(double a, double b)

intResult = calculate()

2. Give the signature for a method that can be used to accomplish each of these tasks. Do not write the full method, only give the signature.

(A) A method that returns the middle of three given integers. If the method is given 5, 3, and 9, it would return 5.

(B) A method that takes three Strings, a first, middle, and last name and returns the last name, followed by a comma and the first name and the middle name.

(C) A method that takes a number of repeats and a character and returns a String containing the character repeated the number of repeats times. If the method was given 3 and 'a' it would return "aaa".

int calculate()

doubleResult = calculate(3, 9.5)

int calculate(int a, double b)

doubleResult = calculate(2.7, 3.9)

void calculate (int a, int b, int c)

calculate(2, 4, 7)

double calculate(double a, double b)

intResult = calculate()

Explanation / Answer

int calculate()

No Match

doubleResult = calculate(3, 9.5)

int calculate(int a, double b)

4

doubleResult = calculate(2.7, 3.9)

void calculate (int a, int b, int c)

3

calculate(2, 4, 7)

double calculate(double a, double b)

1

intResult = calculate()

Explanation :

doubleResult = calculate(2.7, 3.9)

calculate(2, 4, 7)

intResult = calculate()

This function do not take any parameters and return Int type value. So it will match with int calculate().

doubleResult = calculate(3, 9.5)

(A) A method that returns the middle of three given integers. If the method is given 5, 3, and 9, it would return 5.

int Middle(int,int,int) // "int is a return type and it takes 3 integer parameters"

{

int mid; // this varriable stores the mid element value

//code

return mid; // this is return statement which return the Mid value.

}

(B) A method that takes three Strings, a first, middle, and last name and returns the last name, followed by a comma and the first name and the middle name.

String methodname(String f,String m,String l) // Method return type is String. So dont foget to include "include<string>" header file. because in C/C++ there is no inbuilt data type String.

{

String result; // varriable to store final result

//CODE

return result; // return statement

}

(C) A method that takes a number of repeats and a character and returns a String containing the character repeated the number of repeats times. If the method was given 3 and 'a' it would return "aaa".

string methodname(int noOfRepeats, char c) // method will return String and takes 2 parameters no pf times character will repeat and character that you want to repeat.

{

String result; // varriable to store final result

//code

return result; // return statement because method is of type string.

}

int calculate()

No Match

doubleResult = calculate(3, 9.5)

int calculate(int a, double b)

4

doubleResult = calculate(2.7, 3.9)

void calculate (int a, int b, int c)

3

calculate(2, 4, 7)

double calculate(double a, double b)

1

intResult = calculate()