COMP 202 Final: COMP202A Final Exam 2012 Fall

64 views22 pages
First Name:Last Name:
McGill ID:Section:
Faculty of Science
COMP-202A - Foundations of Programming (Fall 2012) - All Sections
Final Examination
December 12, 2012 Examiners: Daniel Pomerantz
14:00 - 17:00 Ioannis Rekleitis
Instructions:
DO NOT TURN THIS PAGE UNTIL INSTRUCTED
This is a closed book examination; only a letter-sized (8.5” by 11”) crib sheet is permitted. This crib sheet can
be single or double-sided; it can be handwritten or typed. Non-electronic translation dictionaries are permitted,
but instructors and invigilators reserve the right to inspect them at any time during the examination.
Besides the above, only writing implements (pens, pencils, erasers, pencil sharpeners, etc.) are allowed. The
possession of any other tools or devices is prohibited.
Answer all questions on this examination paper and return it. If you need additional space, use page 17-
20, or the booklets supplied upon request, and clearly indicate where each question is continued. In order to
receive full marks for a question, you must show all work unless otherwise stated.
This examination has 22 pages including this cover page, and is printed on both sides of the paper. On page 21,
you will find information about useful classes and methods.You may detach page 21 from the examination
if you wish.
1 2 3 Subtotal
/8 /15 /12 /35
4 5 6 7 8 Subtotal
/10 /15 /10 /15 /15 /65
Total
/100
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 22 pages and 3 million more documents.

Already have an account? Log in
COMP-202A - Fall 2012 - Final Examination Page 2
Section 1 - Short questions
[8]
1. (a) Suppose b1 and b2 are both Java boolean expressions. Circle true or false for the value of the boolean
expression
(!(b1 || (!b2))) && ((!b1) || b2) in cases where b1 and b2 have values as in the table.
b1 b2 (!(b1 || (!b2))) && ((!b1) || b2)
True True True False
True False True False
False True True False
False True True False
(b) Without using any library methods or classes, write an expression that will evaluate to true whenever a
char variable crepresents NEITHER an uppercase letter NOR a lowercase letter.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 22 pages and 3 million more documents.

Already have an account? Log in
COMP-202A - Fall 2012 - Final Examination Page 3
[15]
2. In each of the following, you will be shown a small snippet of code written by someone else. In some cases, the
code is not very good and contains bugs because the developers who wrote the code did not go to McGill where
they would have learned better in COMP 202.
You should then write in the box what is printed when the code is executed (or in the case of part d or e write
the answer to the questions). You may assume the code below compiles. (15 points)
Part Answer
a (what prints?)
b (what prints?)
c (what prints?)
d (how many objects exist?)
e (which code is better and why?)
(a) public class PartA
{
public static void swapIntArrays(int[] x, int[] y)
{
int[] temp = x;
x = y;
y = temp;
}
public static void main(String[] args)
{
int[] x = {10, 20, 30};
int[] y = {40, 50, 60};
swapIntArrays(x,y);
System.out.println(x[0] + " " + y[0]);
}
}
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 22 pages and 3 million more documents.

Already have an account? Log in
hwpark22 and 40159 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents