CIS 110 Spring 2013 Make-Up Midterm, 13 February 2013, Answer Key. Miscellaneous

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

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm. Answer Key

CIS Fall 2012 Midterm, 7 June 2012, Answer Key. Miscellaneous

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

CIS Introduction to Computer Programming. 5 October 2012 Midterm

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

COS 126 Midterm 1 Written Exam Fall 2011

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

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CIS Introduction to Computer Programming Spring Exam 1

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

CIS 110 Fall 2015 Introduction to Computer Programming 6 Oct 2015 Midterm Exam Answer Key

CIS 110 Spring 2012 Final Exam, 7 May 2012, Answer Key. Miscellaneous

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

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

CIS 110 Spring 2013 Final Exam, 29 April 2013, Answer Key. Miscellaneous

CIS 110 Fall 2015 Introduction to Computer Programming 7 Oct 2015 Makeup Midterm Exam

Practice Midterm 1. Problem Points Score TOTAL 50

COS 126 General Computer Science Fall Written Exam 1

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

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

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

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

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

COS 126 Midterm 1 Written Exam Fall 2012

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

COS 126 Midterm 1 Written Exam Spring 2015

COS 126 General Computer Science Fall Exam 1

Midterm Examination (MTA)

Question: Total Points: Score:

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

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

CS170 Introduction to Computer Science Midterm 2

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

COMP 110 Programming Exercise: Simulation of the Game of Craps

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

AP Computer Science Unit 1. Programs

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

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

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

CS 139 Practice Midterm Questions #2

Introduction to Computer Science Unit 2. Notes

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

CS 101 Exam 2 Spring Id Name

COS 126 Midterm 1 Written Exam Fall 2013

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

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

Csci 102: Sample Exam

DATA TYPES AND EXPRESSIONS

CIS 120 Midterm II November 8, Name (printed): Pennkey (login id):

CS 101 Fall 2005 Midterm 2 Name: ID:

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Functions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)

Spring % of course grade

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

Introduction to Computer Science Unit 2. Notes

CS 101 Spring 2007 Midterm 2 Name: ID:

A Foundation for Programming

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

CSE 1223: Exam II Autumn 2016

COS 126 General Computer Science Spring Written Exam 1

University of Palestine. Mid Exam Total Grade: 100

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

Arrays. Eng. Mohammed Abdualal

Statement Basics. Assignment Statements

1. Find the output of following java program. class MainClass { public static void main (String arg[])

CS 177 Spring 2010 Exam I

COS 126 General Computer Science Spring Written Exam 1

Research Group. 2: More types, Methods, Conditionals

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CSE 11 Midterm Fall 2008

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Types in Java. 8 Primitive Types. What if we want to store lots of items e.g. midsem marks?

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

Name CIS 201 Midterm II: Chapters 1-8

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

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Lecture 5: Methods CS2301

Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points.

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

CSE331 Winter 2014, Midterm Examination February 12, 2014

Place your name tag here

ESC101 : Fundamental of Computing

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

1. (18 pts) Short Answer. Provide brief (1-3 sentence) answers to the following:

Backward Reasoning: Rule for Assignment. Backward Reasoning: Rule for Sequence. Simple Example. Hoare Logic, continued Reasoning About Loops

COS 126 Midterm 1 Written Exam, Fall 2009

CONDITIONAL EXECUTION

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

2.3 Recursion 7/23/2015 3:06:35 PM

Following is the general form of a typical decision making structure found in most of the programming languages:

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

Data Structure and Programming Languages

COS 126 Midterm 1 Written Exam Fall 2014!

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

Transcription:

CIS 110 Make-Up 1 CIS 110 Spring 2013 Make-Up Midterm, 13 February 2013, Answer Key Miscellaneous 1. (1 points) (a) Write your name, recitation number, and PennKey (username) on the front of the exam. (b) Sign the certification that you comply with the Penn Academic Integrity Code Truth or Dare 2. (10 points) For each of the following boolean expressions, state whether it is always true (T), always false (F), sometimes true and sometimes false/not enough information to tell (S), will result in a compiler error (CE), or will result in a run-time exception (RE). Assume there are no rounding errors and the variables x and y are ints. (a) 2 * x / 2 == x T (b) 2(3) == 6 CE (c) Math.sqrt(x) * Math.sqrt(x) == x S (d) Double.parseDouble(3.0) == 3.0 CE (e) Double.parseDouble("3") == 3.0 T (f) 1.0 + 2.0 >= 3.0 T (g) x - Math.abs(x - y)!= y S (h) 1 / 0!= 1.0 / 0.0 RE (i) x - y <= x S (j) 3 / 2 < 1.5 T

CIS 110 Make-Up 2 Bugs Bunny 3. (14 points) Identify 7 bugs in the program below that will prevent it from compiling or running. For each bug, give the line number and corrected line of code. Write your answers on the following page. Since this program is loony anyway, we will accept any reasonable fix that allows the program to compile and run without error. You do not need to worry about the program s purpose. 0 public class LittleBunny() { 1 public static void main(string args) { 2 int input = args[0]; 3 if (input < 1) 4 return; 5 double arr = new double[input]; 6 int i; 7 for (int j = 0; j <= arr.length; j += 1) { 8 i = (i + j) % arr.length; 9 arr[j] = foofoo(i, j); 10 System.out.println("" + arr[j]); 11 12 13 14 public static String foofoo(int i, int j) { 15 if (i < j) 16 return "a"; 17 if (i > j) 18 return "b"; 19 20 Bug 1: 0: public class LittleBunny { Bug 2: 1: public static void main(string[] args) Bug 3: 2: int input = Integer.parseInt(args[0]) Bug 4: 5: String[] arr = new String[input] Bug 5: 6: int i = 0; Bug 6: 7: for (int j = 0; j < arr.length; j += 1) Bug 7: 17: else -or- if (i >= j) -or- insert add return statement at line 19 -orremove line 17.

CIS 110 Make-Up 3 A Square Meal 4. (20 points) Each of the four figures below can be created by calling a recursive function recursive(3, 0.5, 0.5, 0.25) whose arguments are the recursive depth, x and y positions, and size. In each case, you can implement the function by reordering the six lines of code given below. Assume the drawsquare() function exists and draws a gray square with a black outline. For each of the four figures, put the six lines of code in the correct order to generate the figure. You only need to give the numbers of each line; you do not need to rewrite them. public static void recursive(int n, double x, double y, double sz) { 1: recursive(n - 1, x - sz, y + sz, sz / 2) // upper left 2: recursive(n - 1, x + sz, y + sz, sz / 2) // upper right 3: recursive(n - 1, x + sz, y - sz, sz / 2) // lower right 4: recursive(n - 1, x - sz, y - sz, sz / 2) // lower left 5: drawsquare(x, y, sz) 6: if (n == 0) return; Line 2: 5 Line 3: 4 Line 4: 1 Line 5: 3 Line 6: 2 Line 1: 5 Line 2: 6 Line 3: 4 Line 4: 1 Line 5: 3 Line 6: 2 Line 2: 4 Line 3: 2 Line 4: 5 Line 5: 1 Line 6: 3 Line 2: 4 Line 3: 1 Line 4: 3 Line 5: 2 Line 6: 5

CIS 110 Make-Up 4 Recess 5. (20 points) Read the code below, then answer the questions on the next page: (a) What does the command java Playground 1 2 5 3 print? Circle your answer. 67-72-79-67-83 (The ASCII character codes for CHOCS) (b) What does the command java Playground 2 2 print? Circle your answer. 82.0 (The ASCII code for R) (c) What does the command java Playground 3 print? Circle your answer. YUM (d) Describe in 20 words or less what slide() computes. You may assume that a, b, and c are all at least zero. Circle your answer. Return a 2 b + c. (e) Describe in 20 words or less what monkeybars() doess. You may assume that a is at least zero. Circle your answer. Increases a by 2 until exceeds 80, then returns it.

CIS 110 Make-Up 5 What a Dupe 6. (25 points) This question consists of three parts on three pages. For each part, you only need to write the prescribed function; you do not need to write the surrounding class. You also do not need to write any comments. (a) Write a function contains() that takes an integer x and an array of integers arr, and returns true or false depending on whether or not arr contains the value x. You may assume that arr contains at least one element. public static boolean contains(int x, int[] arr) { for (int i = 0; i < arr.length; i++) if (arr[i] == x) return true; return false; (b) Write a function dupes() that accepts two arrays of integers and uses the contains() function to compute and return the number of values that occur in both arrays. Your solution must not be recursive. You may assume that each array contains at least one value, that no value occurs more than once within either array, and that the contains() function is defined in the same class as dupes(). public static int dupes(int[] arr1, int[] arr2) { int d = 0; for (int i = 0; i < arr1.length; i++) if (contains(arr1[i], arr2)) d++; return d; (c) Write a recursive function, dupes2() that accepts two arrays of integers and an integer n. dupes2(arr1, arr2, n) should do the same thing as dupes() use the contains() function to compute and return the number of values that occur in both arr1 and arr2 except that it should only consider values in entries n and higher of arr1. dupes2(arr1, arr2, 0) should therefore return the same result as dupes(arr1, arr2). dupes2() must not contain any loops and must not call dupes(). You may assume that each array contains at least one value, that no value occurs more than once within either array, and that the contains() function is defined in the same class as dupes2(). You may also assume that dupes2() will only be called with a value of n that is at least 0. public static int dupes2(int[] arr1, int[] arr2, int n) { if (n >= arr1.length) return 0; if (contains(arr1[n], arr2)) return 1 + dupes2(arr1, arr2, n + 1); else return dupes2(arr1, arr2, n + 1);