New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

Similar documents
New York University Introduction to Computer Science Midterm2B Sample Problems Solution Key. Instructions:

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 113 PRACTICE FINAL

Final Exam Practice. Partial credit will be awarded.

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

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

Question: Total Points: Score:

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

Object Oriented Programming. Java-Lecture 6 - Arrays

Bjarne Stroustrup. creator of C++

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

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

Wrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321

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

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

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

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

ITERATION WEEK 4: EXMAPLES IN CLASS

Timing for Interfaces and Abstract Classes

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Chapter 3. Ch 1 Introduction to Computers and Java. Selections

Structures and Pointers

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

Final Exam. COMP Summer I June 26, points

CMPS 11 Introduction to Programming Midterm 1 Review Problems

Lecture 12. Data Types and Strings

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 251 Intermediate Programming More on classes

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

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

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Midterm Examination (MTA)

CIS Introduction to Computer Programming. 5 October 2012 Midterm

AQA Decision 1 Algorithms. Section 1: Communicating an algorithm

CSE 1223: Exam II Autumn 2016

H212 Introduction to Software Systems Honors

I. True/False: (2 points each)

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CSC-140 Assignment 6

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

Announcements. 1. Forms to return today after class:

CS 101, Spring 2016 March 22nd Exam 2

CS100J February 13, 2001

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CSEN 202: Introduction to Computer Programming Spring term Final Exam

Other conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

PRACTICE MIDTERM EXAM #1

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 113 MIDTERM EXAM 2 SPRING 2013

Simplified Operating Instructions T105-C / T108-C / T106-C / T17B-C DISPLAYS DAY OR DAY BLOCK PROG 00:0000 PROG PROG ALWAYS OFF

Chapter 3. Selections

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CONTENTS: Arrays Strings. COMP-202 Unit 5: Loops in Practice

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

Loops. CSE 114, Computer Science 1 Stony Brook University

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

CSE 131 Introduction to Computer Science Fall Exam II

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Letterkenny Institute of Technology

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

CS141 Programming Assignment #5

Lecture 8 " INPUT " Instructor: Craig Duckett

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CS 455 Midterm Exam 1 Fall 2013 [Bono] Wednesday, Oct. 2, 2013

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

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

Scheduling WebEx Meetings with Microsoft Outlook

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Faculty of Science Midterm. COMP-202B - Introduction to Computing I (Winter 2008)

Computer Science is...

Cloning Enums. Cloning and Enums BIU OOP

Controls Structure for Repetition

Armstrong State University Engineering Studies MATLAB Marina Switch-Case Statements Primer

Problem Points Score Grader Total 75

Programming Karel the Robot

Using Variables to Write Pattern Rules

Transcription:

Name: New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided (front and back)! No calculators, notes, textbooks, or any other aids are allowed except writing utensils (pens, pencils, crayons, erasers, etc.) or other aids provided to you by the instructor. If you need extra scratch paper, please pick it up from the front of the class. You should also be provided with an appendix that provides helpful documentation. All answers must be submitted on (or attached to) this exam sheet. All answers must be clearly legible. Commenting code: Comments aren't required, but if you provide good comments, they can earn you partial credit if your code isn't correct. Total Points Available: Total Missed: Final Score: 1

Example True or False (10 points): Instructions: Circle either True or False based on the validity of the statement. 1. A String is a mutable data type. statement = true statement = false; [There are usually 5-10 questions of this type] 2

Example Multiple Choice (10 points): Instructions: Circle the letter of the best answer. 1. Given a string variable named 'foo' that contains a string Where in the world is Carmen Sandiego?, what would foo.charat(foo.length() - 1) return? A. 'W' B. 'n' C. '?' D. 'o' E. 'h' [There are usually 5-10 questions of this type] 3

Example Short Answer (10 points): Instructions: In your own words, answer the questions as best as possible in one or two sentences. 1. What is the difference between a Class and an Object. [There are usually 5-10 questions of this type] 4

Example Entomology - Study of Bugs (10 points): Instructions: Find 3 bugs in the following program (there are more than three): 1) Specify the line number of the bug (Note: there can be more than one bug per line) 2) Check the box next to the type of error; either Logic for logic errors or Other for (syntax, type, etc.). 3) Write a short explanation or fix for the error. 1 / 2 Exercise06_03: Count occurrences of numbers entered (values between 3 <code>start_num_range</code> and <code>end_num_range</code>) 4 / 5 public class Exercise06_03 { 6 public static final int START_NUM_RANGE = 1; 7 public static final int END_NUM_RANGE = 100; 8 9 / 10 Main program driver 11 @param args is ignored 12 / 13 public static void main(string[] args) { 14 // Initialize counter array (using one extra index to simply logic) 15 int[] number_counter = new int(end_num_range + 1); 16 17 // Get user inputed values 18 Scanner scanner = Scanner(System.in); 19 System.out.print("Enter integers between " 20 + START_NUM_RANGE + " and " + END_NUM_RANGE + ": "); 21 int input = scanner.next(); 22 while (input!= 0) 23 number_counter[input] + 1; // update counter 24 input = scanner.nextint(); // get next input 25 26 27 // Print out count for values that were encountered 28 for (int i = 0; i <= number_counter.length(); i++) { 29 if (number_counter[i] == 0) { 30 System.out.println(i + " occurs " + number_counter[i] + " time"); 31 else if (number_counter[i] > 1) { 32 System.out.println(i + " occurs " + number_counter[i+] + " times"); 33 34 35 36 Bug Line # Type of Error 1 [ ] Logic [ ] Other 2 [ ] Logic [ ] Other 3 [ ] Logic [ ] Other Explanation or Fix 5

Example What is the Output (10 points): Instructions: What is the output if the following code is run? 1 public class OutputSample { 2 public static void main(string[] args) { 3 int[] ints = { 9, 8, 5, 4, 6, 7, 1, 2, 3 ; 4 rearrange(ints); 5 for (int value : ints) { 6 System.out.print(value + " "); 7 8 9 10 / 11 Takes an array and swaps values from two positions 12 / 13 public static void swap(int[] ints, int index1, int index2) { 14 int temp = ints[index1]; 15 ints[index1] = ints[index2]; 16 ints[index2] = temp; 17 18 19 public static void rearrange(int[] ints) { 20 // for the number of elements in ints 21 for (int count = 0; count < ints.length; count++) { 22 // for every pair of elements 23 for (int i = 1; i < ints.length; i++) { 24 // if current element is smaller than the the next element, swap those values 25 if (ints[i - 1] < ints[i]) { 26 swap(ints, i - 1, i); 27 28 29 30 31 Answer: 6

Example Comment the Code (10 points): Instructions: The following code was written, but the documentation was left out. Analyze the code to determine what each function does and then what the program as a whole does. Fill in the missing comments. Be as specific as possible. Remember that Javadocs should explain WHAT the code does, and inline comments are generally best if they explain why the code is doing what it does. / / static int[] dostuff(int size, int min, int max) { Random rand = new Random(); // int[] ints = new int[size]; // for (int i = 0; i < ints.length; i++) { int nextrandom = rand.nextint(max-min + 1); // nextrandom += min; // ints[i] = nextrandom; return ints; / / static int dosomething(int[] ints) { int sum = 0; // for (int i = 0; i < ints.length; i++) { sum += ints[i]; return sum; 7

Example Fill in the Code (10 points): Instructions: Fill in the missing code. public enum Day { SUNDAY, MONDAY, WEDNESDAY, TUESDAY, THURSDAY, FRIDAY, SATURDAY; / @return true if Day is a weekend, otherwise false / isweekend() { switch(this) { case : case : return true; : return false; / @return true if Day is a weekday, otherwise false / isweekday() { return! ; / Implicitly called when a string representation is requested / public tostring() { switch(this) { case SUNDAY: return "Sunday"; case MONDAY: return "Monday"; case TUESDAY: return "Tuesday"; case WEDNESDAY: return "Wednesday"; case THURSDAY: return "Thursday"; case FRIDAY: return "Friday"; case SATURDAY: return "Saturday"; / @return the Day of the week immediately following this Day. / gettomorrow() { switch(this) { case SUNDAY: return MONDAY; case MONDAY: return TUESDAY; case TUESDAY: return WEDNESDAY; case WEDNESDAY: return THURSDAY; case THURSDAY: return FRIDAY; case FRIDAY: return SATURDAY; case SATURDAY: return SUNDAY; 8

9

Example Write the Code: In java code, write a class that has the following data and methods: Ball: ---data----------------- - xposition: int - yposition: int - xspeed: int - yspeed: int - size: int ---methods------------ + Ball() + Ball(xPosition: int, yposition: int, xspeed: int, yspeed: int, size: int) + updateposition() + reversespeedy() + reversespeedx() [There are usually about 3 of these types of questions] 10