Confidential Teaching Materials:
Quiz 2 Grading Criteria
Note: To receive any credit whatsoever, the date, your name, your student number, and your answers must
be legible and readily readable in the judgment of the grader.
Add brief explanatory comments as necessary to make sure your answers are clear and unambiguous
to the grader.
[p1] 25.0 points
Write a module that takes in two numbers, adds 5 to the first one and 10 to the second one and then returns the
modified numbers to the calling algorithm.
LINES=15
[c1] 25 points
Example solution: (many possible reasonable particulars)
[p2] 25.0 points
Write a module that will be passed three numbers and return the minimum value among them. You may assume
that the three numbers are unique, i.e., no duplicate values among them.
LINES = 15
[c2] 25 points
Confidential Teaching Materials:
Quiz2 Criteria, page 2 of 4
+2 (x3) for each correct test/return pair(LOG, WRT, RET)
Example solution: (numerous possible reasonable solutions)
function Min_Of_Three returnsa Num (num_1, num_2, num_3 isoftype in Num)
if ((num_1 < num_2) AND (num_1 < num_3)) then
Min_Of_Three returns num_1
elseif (num_2 < num_3) then
Min_Of_Three returns num_2
else
Min_Of_Three returns num_3
endif
endfunction //MinOfThree
[p3] 25.0 points
Write an algorithm that will prompt the user for three numbers, and print the smallest value among them. You
may use any module you have written so far.
LINES = 15
[c3] 25 points
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”.
Confidential Teaching Materials:
Quiz2 Criteria, page 4 of 4
-print statement need to be reformatted to print the value of the
variable answer. Right now it prints the word answer.
c) -parameter needs to be declared as in, not in/out
-the strings that are returned need to be changed to their boolean
equivalent
-missing “end” should be “endfunction”
-2.5 points for each error left uncorrected (WRA)
-2.5 points for a non-error correction that makes things worse.