Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Similar documents
Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2015) - All Sections Midterm Examination

Faculty of Science COMP-202B - Foundations of Computing (Winter 2016) - All Sections Midterm Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2011) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination

Faculty of Science COMP-202B - Foundations of Computing (Winter 2016) - All Sections Final Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2014) - All Sections Final Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Final Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault

COMP102: Test. 26 April, 2006

Computer Science 300 Sample Exam Today s Date 100 points (XX% of final grade) Instructor Name(s) (Family) Last Name: (Given) First Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

Computational Expression

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

Full file at

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Computer Science 145 Midterm 1 Fall 2016

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

Using Java Classes Fall 2018 Margaret Reid-Miller

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

COMP102: Test 1 Model Solutions

A variable is a name for a location in memory A variable must be declared

File I/O Array Basics For-each loop

CS 211: Existing Classes in the Java Library

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

We now start exploring some key elements of the Java programming language and ways of performing I/O

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

Programming with Java

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

A Quick and Dirty Overview of Java and. Java Programming

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

I. True/False: (2 points each)

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Name CIS 201 Midterm II: Chapters 1-8

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

b. Suppose you enter input from the console, when you run the program. What is the output?

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

COMP102: Test 2 Model Solutions

ing execution. That way, new results can be computed each time the Class The Scanner

Final Exam Practice. Partial credit will be awarded.

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

Classes and Objects Part 1

Computer Programming, I. Laboratory Manual. Final Exam Solution

1. An operation in which an overall value is computed incrementally, often using a loop.

Text User Interfaces. Keyboard IO plus

Midterm Exam CS 251, Intermediate Programming March 12, 2014

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Place your name tag here

CIS 110 Introduction to Computer Programming Fall 2017 Midterm. Recitation ROOM :

H212 Introduction to Software Systems Honors

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

COMP200 INPUT/OUTPUT. OOP using Java, based on slides by Shayan Javed

Section 2: Introduction to Java. Historical note

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CSE 1223: Exam II Autumn 2016

Midterm 1 Written Exam

Sample Examination Paper Programming and Software Development

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Appendix 3. Description: Syntax: Parameters: Return Value: Example: Java - String charat() Method

CS Final Exam Review Suggestions - Fall 2017

CS 101 Spring 2007 Midterm 2 Name: ID:

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

Computer Center. Texas Tech University. Quick Reference Guide For Testing

AP Computer Science Java Mr. Clausen Program 6A, 6B

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

COS 126 Midterm 1 Written Exam, Fall 2009

CS Final Exam Review Suggestions - Spring 2014

CSE 142, Spring 2009, Final Exam

COMP 202 Java in one week

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2009

CSCI 2101 Java Style Guide

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

CIS 130 Exam #2 Review Suggestions

Transcription:

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. 6. Using a variable without declaring it. 7. Accessing an array out of bounds. 8. Storing an int expression into a variable of type double. 9. Incorrect indentation 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; return x; (A) 1 3 (B) 2 3 (C) 3 2 (D) 2 3 (E) 2 2 11. What value is returned by the following method if the input array is { 2, 3, 4, 1, 2, 1 public static int mystery(int[] array) { int foo = 0; for (int i = 0; i < array.length; i++) { if (i % 2 == 0) { foo = foo - array[i]; else { foo = foo + array[i]; return foo; (A) 3 (B) -3 (C) 5 (D) -5 (E) 13 12. How many times does the letter A print in the following code? for (int i = 0; i < 6; i++) { for (int j = 2; j <= 5; j+= 2) { System.out.println("A"); (A) 0

COMP-202A - Fall 2013 - Midterm Examination Page 6 (B) 4 (C) 12 (D) 20 (E) 30 13. How many times does the letter B print in the following code? for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { System.out.println("B"); System.out.println("B"); System.out.println("B"); (A) 8 (B) 18 (C) 24 (D) 30 (E) 36 14. What String does the following code return if the input to the method is the String with contents ABCD. public static String mystery(string input) { String tricky = ""; for (int i = 0; i < input.length(); i++) { tricky = (char) (input.charat(i) + 3); return tricky; (A) ABCD (B) BCDE (C) CDEF (D) DEFG (E) There is a compiler error because you can t add a char to an int. True false questions In the following questions answer A for true or B for false. 15. In Java, all variables must be declared

COMP-202A - Fall 2013 - Midterm Examination - Appendix Page 7 16. In Java, all method must be commented. 17. A String can be cast to an int by writing (int) before the String expression. 18. In Java, loops are allowed inside of other loops 19. A method can return more than one value in Java. SUMMARY OF JAVA STANDARD LIBRARY METHODS FOR SELECTED CLASSES String (package java.lang) Methods: public boolean equals(object anobject): Compares this String to anobject. public int length(): Calculates the length of this String. public boolean equalsignorecase(string anotherstring): Compares, ignoring case considerations, this String to anotherstring. public int compareto(string anotherstring): Compares this String to anotherstring lexicographically; returns a negative value if this String occurs before anotherstring, a positive value if this String occurs after anotherstring, and 0 if both Strings are equal. public int comparetoignorecase(string anotherstring): Compares, ignoring case considerations, this String to anotherstring lexicographically; returns a negative value if this String occurs before anotherstring, a positive value if this String occurs after anotherstring, and 0 if both Strings are equal. public String substring(int start, int finish): Returns a new String composed of the this String starting from index start and up to, but not including index of finish public String replace(char c, char d) : Returns a new String with all occurrences of the character c in the this String replaced by the character d. public char[] tochararray(): Converts this String to a new character array. File (package java.io) Methods: public FileSstring pathname): Creates a new File instance that corresponds to the given pathname. Scanner (package java.util) Methods: public Scanner(Inputstream source): Constructs a new Scanner that produces values scanned from the specified input stream. public Scanner(File f): Constructs a new Scanner that produces values scanned from the specified File public double nextdouble(): Scans the next token of the input as a double. public boolean nextboolean(): Scans the next token of the input as a boolean. public int nextint(): Scans the next token of the input as an int. public String nextline(): Advances this Scanner past the current line and returns the input read. public boolean hasnextline(): Checks whether there are further lines left to scan. PrintStream (package java.io) Methods: public void print(boolean b): Prints boolean value b. public void print(double d): Prints double value d. public void print(int i): Prints int value i. public void print(object o): Prints Object o. public void print(string s): Prints String s. public void println(): Terminates the current line by writing the line separator string.

COMP-202A - Fall 2013 - Midterm Examination - Appendix Page 8 public void println(boolean b): Prints boolean value b and then terminates the line. public void println(double d): Prints double value d and then terminates the line. public void println(int i): Prints int value i and then terminates the line. public void println(object o): Prints Object o and then terminates the line. public void println(string s): Prints String s and then terminates the line. Math (package java.lang) Methods: public static double pow(double a, double b): Returns the value of a raised to the power of b. public static double sqrt(double a): Returns the correctly rounded positive square root of double value a. public static double random(): Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. public static double exp(double a): Returns Euler s number e raised to the power of double value a. (base e) of double value a. of double value a.

COMP-202A - Fall 2013 - Midterm Examination - Appendix Page 9 Solutions to above questions 1 B 2 E 3 E 4 E 5 D 6 A 7 B 8 E 9 D 10 B (or D since they are the same!) 11 B 12 C 13 E 14 D 15 A 16 B 17 B 18 A 19 B