COMP-202--midterm-exam--2009-11

COMP-202--midterm-exam--2009-11 - First Name : Last Name :...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: First Name : Last Name : McGill ID : Section : Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination Tuesday, November 3, 2009 Examiners: Mathieu Petitpas [Sections 1 and 3] 18:30–20:30 Kamal Zellag [Section 2] Instructions: • DO NOT TURN THIS PAGE UNTIL INSTRUCTED • This is a closed book midterm examination; notes, slides, textbooks, and other forms of documenta- tion are not allowed. • Non-programmable calculators are allowed (though you should not need one). • Computers, PDAs, cell phones, and other electronic devices are not allowed. • Answer all questions on this examination paper and return it. If you need additional space, use page 18 or the booklets supplied and clearly indicate where each question is continued. In order to receive full marks for a question, you must show all work. • This midterm examination has 20 pages including this cover page, and is printed on both sides of the paper. Pages 19-20 contain information about useful classes and methods. 1 2 3 4 Subtotal /6 /6 /4 /4 /20 5 6 Subtotal /15 /15 /30 7 8 Subtotal /15 /35 /50 Total /100 1 COMP-202A - Fall 2009 - Midterm Examination Page 2 Section 1 - Short Questions 1. In one or two sentences, explain the main differences between the concepts in each of the following [6] pairs. BE BRIEF ; overly long answers will be grounds for mark deductions. (a) An if statement and a while statement (b) The && operator and the || operator (c) Formal parameters and actual parameters COMP-202A - Fall 2009 - Midterm Examination Page 3 2. What will be displayed to the screen after each of the following code fragments is executed? For full [6] marks, describe BRIEFLY with a few words and a value what happens at intermediate steps. (a) int a = 5; int b = a % 2; double c = a / 10; double d = b + 2.5; double e = (int)d * 3; System.out.println("c == " + c + ", e == " + e); (b) int a1 = {5, 10, 20, 0}; int a2 = a1; a2[0] = 3; boolean b = a1[1] + a1[2] == a1[0] + a1[3]; System.out.println(a1[1] + a1[2] + " == " + a1[0] + a1[3] + ": " + b); COMP-202A - Fall 2009 - Midterm Examination Page 4 3. The following program prints a shape to the screen using the character * . Describe what shape it is [4] and what its dimensions are. You can also draw the program’s exact output for full marks. public class MysteryShape { public static void main(String args) { final int SIZE = 15; final int HALF_SIZE = SIZE / 2; int side; for (int i = 0; i < SIZE; i++) { if (i <= HALF_SIZE) { side = i; } else { side = SIZE - (i + 1); } for (int j = 0; j < SIZE; j++) { if (HALF_SIZE - side <= j && j <= HALF_SIZE + side) { System.out.print(" * "); } else { System.out.print(" "); } } System.out.println(); } } } COMP-202A - Fall 2009 - Midterm Examination Page 5 4. Consider the swap() method, declared in the following Swapper class: [4] public class Swapper { public static void swap(int a, int b) { int temp; temp = a; a = b; b = temp; } public static void main(String args) {...
View Full Document

This note was uploaded on 10/16/2010 for the course COMP 202 taught by Professor Verbrugge during the Winter '07 term at McGill.

Page1 / 20

COMP-202--midterm-exam--2009-11 - First Name : Last Name :...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online