9 Pages
Unlock Document

McGill University
Computer Science (Sci)
COMP 202
Daniel Pomerantz

First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination November 11th, 2013 Examiners: Jonathan Tremblay [Sections 3 (3:30-4:30) and 2 (1:00-2:30)] 18:00-21:00 Dan Pomerantz [Section 1 (10:30-11:30)] 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 the scantron sheet. ▯ This examination has 8 pages including this cover page, and is printed on both sides of the paper. On page 7, you will find information about useful classes and methods. You may detach page 7 from the examination if you wish. ▯ MAKE SURE TO WRITE YOUR NAME AND STUDENT ID ON THE SCANTRON AS WELL AS TO FILL IN THE BUBBLE PROPERLY AT THE BEGINNING OF THE EXAM COMP-202A - Fall 2013 - Midterm Examination Page 2 Practice exam The following is designed to give you some practice with answering multiple choice questions. Solutions are listed below. We strongly suggest that you take this exam by writing down all your answers on a separate piece of paper, double checking your work, and only then looking at the solutions to confirm your answers. This is not meant to be a simulation of the real exam in that the exact length may be a bit different. Some notes on your real midterm exam: 1. There are approximately 50 questions total. 2. Of these, approximately 24 are separate questions (worth 2 points each), 14 are linked questions (worth 3 points each) referring to the same piece of code and asking many questions about it, and 10 are true false (worth 1 point each) 3. For the group of questions referring to the same piece of code, it is very important to know your assignments inside and out as the code will share some relation to that. 4. There is no penalty for guessing, so you should guess! 5. All questions within a section are weighted equally, so remember not to waste too much time on one question. 6. You are allowed to bring with you a crib sheet to the exam. The crib sheet can be two sided and typed and you can put whatever you want on it. We recommend putting examples that you found particularly tricky or confusing on it to help you. The point is not to make you memorize random facts that you’ll forget afterwards anyway and in fact preparing the crib sheet (and selecting the important bits) can be a key part of studying. 7. Remember that the midterm is designed to be practice for the final. So even though there is an option in the final grading to skip your midterm grade, it is strongly recommended you take the midterm as seriously as possible. 8. There are other old midterms posted. Although there is no programming question on the exam, you can still use the old midterms to practice because the short answer format is similar. The main difference is you now are given choices instead. 9. Good luck! COMP-202A - Fall 2013 - Midterm Examination Page 3 1. Which of the following is NOT a legal Java statement: (A) int x = 2; (B) double x = 4 + "" + 3; (C) double x = 3.0 + 4; (D) String x = "7 / 2"; (E) int x = 3; 2. How many times is the condition of the while loop checked in the following code? int i = 0; while (i < 30) { System.out.println("Repeat!"); i = i + 2; } (A) 15 (B) 30 (C) 10 (D) 1 (E) 16 3. Suppose you have a method with the following header: public static void fun(String x, boolean b) Which of the following are legal ways to call the method: ▯ I. fun("3 + 1", true); ▯ II. fun(3 + "", false); ▯ III. fun("3.0", !true); (A) I only (B) II only (C) III only (D) II and III (E) I, II, and III 4. Which of the following Java expressions do not have a value of true? (A) true (B) !!true (C) !false (D) ! (false && true) (E) ! (false —— true) COMP-202A - Fall 2013 - Midterm Examination Page 4 Type of Errors For each of the following answer whether they would cause an compiler error, runtime error, or a bug. In other cases the mentioned error may not cause a problem for the computer and is merely a question of style. In this case you should choose “Style” In other cases the question may not cause a problem at all in which case you should answer ”No Error” For example, omitting a statement may lead to any of the above errors depending on where the omission occurred. 5. Omitting comments from your code. (A) Compiler Error (B) Runtime Error (C) Bug (logical) Error (D) Style (E) No Error 6. Using a variable without declaring it. (A) Compiler Error (B) Runtime Error (C) Bug (logical) Error (D) Style (E) No Error 7. Accessing an array out of bounds. (A) Compiler Error (B) Runtime Error (C) Bug (logical) Error (D) Style (E) No Error 8. Storing an int expression into a variable of type double. (A) Compiler Error (B) Runtime Error (C) Bug (logical) Error (D) Style (E) No Error 9. Incorrect indentation (A) Compiler Error (B) Runtime Error (C) Bug (logical) Error (D) Style (E) No Error 10. What prints as a result of the following code being run? COMP-202A - Fall 2013 - Midterm Examination Page 5 public static void main(String[] args) { int x = 1; int y = 3; x = foo(x,y); System.out.println(x + " " + y); } public static int foo(int x, int y) { x = x * 2; y = x;
More Less

Related notes for COMP 202

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.