Confidential Teaching Materials:
Quiz 6 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.
Use the following type definitions for questions 1 and 4.
Baseball_Card definesa record
name isoftype String
homeruns isoftype Num
cash_value isoftype Num
endrecord // Baseball_Card
Collection definesa record
data isoftype Baseball_Card
left isoftype ptr toa Collection
right isoftype ptr toa Collection
endrecord // Collection
[p1] 30 points
You have information about your baseball card collection stored in a binary search tree. The information is
ordered by the number of homeruns that a player has hit. Write a module that will receive a baseball card
collection and will return the cash value of the entire collection.
LINES=25
[c1] 30 points
30 points
Confidential Teaching Materials:
[p2] 25 points
Write a module that will print all of the numbers in a two dimensional (25 rows x 50 columns) array of numbers.
Be sure to include any necessary type declarations.
LINES=59
[c2] 25 points
25 points
Confidential Teaching Materials:
[p3] 15 points
Identify and correct any errors in the following code. Assume that the comments are complete and correct.
MAX is 100
An_Array definesa array of Char
function Num_Occurrences_Of_Char isoftype Num (An_Array isoftype in array,
count_char isoftype in Char)
//Returns the number of occurances of count_chars in an array
occurrences isoftype Num
index isoftype Num
loop
exitif (index = MAX)
if (new_array[index] = count_char) then
occurrences <- occurrences + 1
endif
index <- index + 1
endloop
Num_Occurrences_Of_Char returns occurrences
endfunction
LINES = 6
[c3] 15 points
Error corrections (other possible ways to repair):
An_Array definesa array[1..MAX] of Char
Quiz 6 Grading Criteria, Page 4 of 5
[p4] 15 points
Identify and correct any errors in the following code. You may assume that the comments are complete and
correct. Remember that the type declarations for this module are at the beginning of the quiz.
procedure Add_Card (new_card isoftype in Baseball_Card,
my_collection isoftype in ptr toa Collection)
//Adds a card to the collection in the correct place.
//Precondition: my_collection is a BST sorted on the homerun field.
//Postcondition: my collection has the new card inserted in the appropriate
// location.
if (my_collection = NIL) then
temp^.data <- new_card
temp^.left <- NIL
temp^.right <- NIL
my_collection <- temp
elseif (new_card^.homerun > my_collection^.data.homerun) then
Add_Card (new_card, my_collection^.right)
else
Add_Card (new_card, my_collection^.left)
endif
endprocedure // Add_Card
LINES=8
[c4] 15 points
Error corrections (other possible ways to repair):
[p5] 15 points
Given the following BST, what is the output that is printed for the following code segment.
12
/ \
/ \
/ \
9 27
/ \ / \
8 10 24 34
/ / / \
7 14 28 41
/ \
4 18
\ \
6 21
Confidential Teaching Materials:
Tree_Node definesa record
data isoftype Num
left isoftype ptr toa Tree_Node
right isoftype ptr toa Tree_Node
endrecord // Tree_Node
procedure Special_Print (my_tree isoftype in ptr toa Tree_Node)
if(my_tree <> NIL) then
if (my_tree^.data MOD 2 = 0 ) then
print(my_tree^.data)
Special_Print(my_tree^.left)
Special_Print(my_tree^.right)
else
Special_Print(my_tree^.left)
print(mytree^.data)
Special_Print(my_tree^.right)
endif
endif
endprocedure // Special_Print
LINES=10
[c5]