Confidential Teaching Materials:
Quiz2 Criteria, page 3 of 4
min isoftype Num
min <- MinOfThree(num_1, num_2, num_3)
print(“The minimum number is:”, min)
endalgorithm //PrintMin
Note: it is perfectly correct to print the function:
print(“The minimum number is:”, MinOfThree(num_1, num_2, num_3))
So don’t take off points for that!
[p4] 25.0 points
Correct the errors in the following code. You may assume all comments are complete and correct.
a. function Cube returnsa Num (num1 isoftype Num)
//Takes in a number via parameter and returns the cube of the number
returns (num1 * num1)
endfunction //Cube
b. function PrintSum (num1, num2 isoftype out Num)
//Takes in 2 numbers via parameter and prints the sum to the screen
answer isoftype Num
answer <- num1 + num2
print (“The answer is:, answer”)
endprocedure //PrintSum
c. function Is_Odd returnsa Boolean (num_to_check isoftype in/out Num)
//Takes in a number via parameter and returns whether or not the
//number is odd (True or False); NOTE: MOD returns the remainder from
//division, ex. 5 MOD 3 = 2
if (num_to_check MOD 2 = 0) then
IsOdd returns “The number is Even”
else
IsOdd returns “The number is Odd”
endif
end // Is_Odd
[c4] 25 points
the errors are as follows:
a) -parameter num1 should be declared as “in”.