CSE 1302C Midterm_Exam_FA11.docx

advertisement
CSE 1302C – Midterm
9/28/2011
NAME:_____________________________________
Directions: You have 90 minutes to complete both sides of this exam. All answers are to be your own (no
cheating!) Each question is worth 25 points.
Question 0: Imagine we are creating a game about a hero who fights a wide variety of creatures,
including 3 kinds of slimy creatures and 2 kinds of fluffy creatures. All of these kinds of creatures have a
position, an amount of damage and a name (e.g. “Bob”). However, each kind of creature attacks our
hero differently. Design a class hierarchy (i.e. a UML diagram) that demonstrates this.
Question 1: Show a code example of polymorphism using your diagram from the previous question.
Then, explain what polymorphism is!
Question 2: Create a list of creatures, and then populate it with 1000 slimy creatures (whichever slimy
creature you like). Then, make all of those creatures attack!
Question 3: One of the fundamental mathematical structures in computer graphics is a matrix, which is
comprised of a series of rows and columns; it’s essentially a 2D array of ints. A matrix is considered to
be an identity matrix if its width and height are the same, and the diagonal is comprised of 1’s and all
other elements are 0’s (see below). Write a function that takes in a 2D array of ints, as well as the width
and height of the array (which are the same value) - and determines whether or not it is an identity
matrix.
1
0
0
0
[0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1]
Download