CMIS 102 Function Practice

Here are some problems to help you practice your understanding of pseudo-coded functions.

1.Here is a function header, identify the following items:
integer getLargest (int x, int y, int z)
1. The function name
2. The function return type
3. The function parameter names
4. The function parameter types
2.Here is a function header, identify the following items:
double average (int a, int b, int m, int n)
1. The function name
2. The function return type
3. The function parameter names
4. The function parameter types
3.Here is a function header, identify the following items:
double temperature (double latitude, double longitude)
1. The function name
2. The function return type
3. The function parameter names
4. The function parameter types
4.Here is a function header, identify the following items:
boolean found (String name, String address, Date birthday)
1. The function name
2. The function return type
3. The function parameter names
4. The function parameter types
5.Here is a function header, identify the following items:
String getCountry (String name, String address, Date birthday)
1. The function name
2. The function return type
3. The function parameter names
4. The function parameter types
6.Given the following function declaration, fill in the body so that the function will return 5 times the first parameter plus 3 times the second
double funOne (double x, double y)
// your code here
return z
end function funOne
7.Given the following function declaration, fill in the body so that the function will return 5 times the parameter squared plus 22.7 times the parameter minus 17.6
double funTwo (double x)
// your code here
return z
end function funTwo
8.Given the following function declaration, fill in the body so that the function will return the sum of the integers between the first and second parameters, inclusive. You may assume that the first parameter is less than the second.
int funThree (int m, int n)
// your code here
return a
end function funThree
9.Given the following function declaration, fill in the body so that the function will return the greatest common divisor of the two parameters. You may assume that the parameters are both greater than 0.
int funFour (int a, int b)
// your code here
return z
end function funFour
10.Given the following function declaration, fill in the body so that the function will return the product of the integers between the two parameters, inclusive. You may assume that the first parameter is less than the second.
int funFive (int m, int n)
// your code here
return z
end function funFive
11.Given the following function declaration, fill in the body so that the function will return the sum of the squares of the integers between the two parameters, inclusive. You may assume that the first parameter is less than the second.
int funSix (int x, int y)
// your code here
return z
end function funSix
12.Given the following function declaration, fill in the body so that the function will write a line of stars, wth the number of stars given by the parameter. Assume that the parameter is greater than 0.
void funSeven (int x)
// your code here
end function funSeven
13.Given the following function declaration, fill in the body so that the function will return true if the parameter is a multiple of 7. You may assume that the parameters is greater than 0.
boolean funEight (int x)
// your code here
return z
end function funEight
14.What is the output of the following function call, given the function shown after main?
main
write nufOne (10)
end main

int nufOne (int n)
int z = 2*n*n*n + 7*n*n + 4*n + 8
return z
end function nufOne
15.What is the output of the following function call, given the function shown after main?
main
write nufTwo (16)
end main

int nufTwo (int n)
int z = 2*n*n*n + 7*n*n + 4*n + 8
return z
end function nufTwo
16.What is the output of the following function call, given the function shown after main?
main
int n
for n = 1 step 3 to 9
write n, ": ", nufThree (n)
end for
end main

int nufThree (int k)
int z = 2*k + 7
return z
end function nufThree
17.What is the output of the following function call, given the function shown after main?
main
nufFive (1, 3, 12)
end m

void nufFive (int a, int b, int c)
int n
for n = a step b to c
write n, ": ", nufFour (n)
end for
end nufFive

int nufFour (int k)
int z = 2*k + 7
return z
end function nufFour
18.What is the output of the following function call, given the function shown after main?
main
int n
for n = 1 step 2 to 10
nufSix ()
end for
write newLine
end main

void nufSix ()
write "*" // no new line here
end nufSix
19.What is the output of the following function call, given the function shown after main?
main
int n, m
for n = 1 step 2 to 10
nufSix ()
end for
write newLine
for m = 3 step 4 to 12
nufSix ()
end for
write newLine
end main

void nufSix ()
write "*" // no new line here
end nufSix
20.What is the output of the following function call, given the function shown after main?
main
int n, m
for n = 1 step 2 to 10
for m = 3 step 4 to 12
nufSix ()
end for
write newLine
nufSix ()
end for
write newLine
end main

void nufSix ()
write "*" // no new line here
end nufSix
21.What is the output of the following function call, given the function shown after main?
main
int n, m
for n = 1 step 2 to 10
for m = 3 step 4 to 12
nufSix ()
write newLine
nufSix ()
end for
end for
write newLine
end main

void nufSix ()
write "*" // no new line here
end nufSix