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

COMP-202--midterm-exam--2009-11 - First Name McGill ID Last...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
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);
Image of page 3

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

View Full Document Right Arrow Icon
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(); } } }
Image of page 4
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) { int v1 = 3; int v2 = 4; System.out.println("Swapping..."); swap(v1, v2); System.out.println("v1’s new value: " + v1); System.out.println("v2’s new value: " + v2); } } The above swap() method above is intended to swap the values of the actual parameters passed to the method. For example, suppose the swap() method works as intended, and the main() method is executed; after the call to the swap() method, the value stored in variable v1
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern