Confidential Teaching Materials:
Quiz 3 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
What is the output of the following algorithm? Include a separate line for each print statement.
//NOTE: the choice of variable/parameter names in the following
// code is intentionally very poor. Do not turn in anything
// like this for homework, or you will face penalties!
algorithm Trace_it_if_you_Can
num1,
num2,
num3 isoftype Num
num1 <- 5
num2 <- 3
num3 <- 7
print(num2, num3, num1)
SwitchAround(num3, num2, num1)
print(num3, num1, num2)
WatchOut(num2, num1, num3)
print(num1, num2, num3)
endalgorithm //Trace_it_if_you_Can
procedure SwitchAround(num1, num2 isoftype in/out Num, num3 is of type in Num)
num1 <- num1 + num2
num2 <- num3
num3 <- num1
print(num1, num2, num3)
endprocedure //SwitchAround
procedure WatchOut(num1 isoftype out Num, num2 isoftype in Num,
num3 isoftype in/out Num)
num1 <- num2 * num3
num2 <- num2 * num3
num3 <- num1 + num2
print(num1, num3, num2)
endprocedure //WatchOut
LINES = 8
[c1] 25 points
Confidential Teaching Materials:
Quiz 3 Criteria, Page 2 of 5
Solution:
3, 7, 5
10, 5, 10
10, 5, 5
50, 100, 50
5, 50, 100
[p2] 20.0 points
Find and correct any errors in the following code. You may assume that the comments are correct. Note that
there may or may not be any errors.
procedure Min_Num (first, second isoftype in Num, answer isoftype out Num)
//The module should find and return the smallest of two numbers
if (first > second) then
answer <- first
else
answer <- second
endif
endprocedure //Min_Num
LINES = 3
[c2] 20 points
[p3] 25.0 points
Write the recursive module Factorial. This module will receive an integer value that is 0 or greater and will return
the factorial of that number. For example: 4! = 4 * 3* 2 * 1 Remember that 0! = 1
LINES = 40
[c3]
Confidential Teaching Materials:
Quiz 3 Criteria, Page 3 of 5
Factorial returns 1
else Factorial returns (number1 * Factorial(number1 – 1))
endif
endfunction //Factorial
25 points
[p4] 30 points
You have recently gotten a job in the payroll department in a large corporation. Your first assignment is to design
a data structure that will hold the following information about each employee:
Employee Name,
Employee numeric ID number,
Employee pay rate per hour,
Number of hours that employee worked this week,
Whether or not the employee worked overtime that week,
Employee’s total pay for the week.
LINES = 15
Next, you must design a module that will be passed one of the data structures that has been filled with data for all
fields except total pay for the week, and will compute the total pay for that employee. In the company that you’re
working for, if an employee works overtime they get a $500 bonus. An employee is considered to have worked
overtime if they worked more than 40 hours. NOTE: remember to use good procedural abstraction in your
answer.
LINES=30
[c4]
Employee definesa record
Confidential Teaching Materials:
Quiz 3 Criteria, Page 4 of 5
Confidential Teaching Materials:
Quiz 3 Criteria, Page 5 of 5
1 point for having them/it be in parameter(s)(INP)
1 point for having an endfunction(MAD)
1 points for having a constant for 40(CON)
2 points for determining if overtime was worked or not(LOG)
2 points for determining total pay(LOG)