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

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

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

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

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

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

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

CIS Introduction to Computer Programming Spring Exam 1

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

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

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

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

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

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

CIS 110 Introduction to Computer Programming Fall 2017 Final Midterm. Recitation Section# :

CIS Introduction to Computer Programming Spring Exam 2

CIS 371 Spring 2015 Computer Organization and Design 7 May 2015 Final Exam

CIS 110 Introduction to Computer Programming Fall 2017 Final Midterm. Recitation Section# :

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

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

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

COS 126 General Computer Science Spring Written Exam 1

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

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

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

COS 126 Midterm 1 Written Exam Fall 2011

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

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution!

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

CS 1301 Exam 1 Fall 2010

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

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

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

EE 312 Fall 2017 Midterm 1 October 12, 2017

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

Final Exam. COMP Summer I June 26, points

CIS 265 Summer 2015 Exam 1 First Name Last Name

Conditionals, Loops, and Style

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

CSE 1223: Exam II Autumn 2016

PRACTICE MIDTERM EXAM #2

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

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

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

STUDENT LESSON A12 Iterations

Conditionals, Loops, and Style. Control flow thus far. if statement. Control flow. Common branching statement Evaluate a boolean expression

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CIS 120 Midterm I October 2, Name (printed): Username (login id):

CSE 131 Introduction to Computer Science Fall Exam I

QUIZ: What value is stored in a after this

COS 126 Midterm 1 Written Exam Spring 2015

CS100J November 20, 2001

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

CS 111X - Fall Test 1

CS 1301 Exam 1 Fall 2010

Question: Total Points: Score:

CSE 303 Midterm Exam

You have three hours to complete this exam. There are 50 total points.

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

COS 126 General Computer Science Fall Written Exam 1

CS Name : Grading TA:

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

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

CSE wi: Practice Midterm

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Name CIS 201 Midterm II: Chapters 1-8

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

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

Learning Goals LG1: Implement the peer instruction process by A) clicking in on an answer B) discussing with your team C) coming to consensus and

CS 1301 Exam 1 Spring 2014

Programming Project: ArrayFun

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

Place your name tag here

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Signature: ECE 551 Midterm Exam

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

Midterm I - Solution CS164, Spring 2014

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

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

Spring 2002: Fundamental Structures of Computer Science

CS 1301 Exam 1 Fall 2014

CMSC 331 Second Midterm Exam

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Java Bytecode (binary file)

Question: Total Points: Score:

CS 101, Spring 2016 March 22nd Exam 2

Examination Questions Midterm 1

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Transcription:

CIS 110 Introduction to Computer Programming Summer 2018 Midterm Name: Recitation ROOM : Pennkey (e.g., paulmcb): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this examination. Signature Instructions: Do not open this exam until told by the proctor. You will have exactly 90 minutes to finish it. Make sure your phone is turned OFF (not to vibrate!) before the exam starts. Food, gum, and drink are strictly forbidden. You may not use your phone or open your bag for any reason, including to retrieve or put away pens or pencils, until you have left the exam room. This exam is closed-book, closed-notes, and closed- com putational devices. If you get stuck on a problem, it may be to your benefit to move on to another question and come back later. All code must be written out in proper java format, including all curly braces and semicolons. Do not separate the pages. You may tear off the one scratch page at the end of the exam. This scratch paper must be turned in or you lose 5 points. Turn in all scratch paper to your exam. Do not take any sheets of paper with you. If you require extra paper, please use the backs of the exam pages or the extra pages provided at the end of the exam. Only answers on the FRONT of pages will be grading. The back is for scratch work only. Use a pencil, or blue or black pen to complete the exam. If you have any questions, raise your hand and a proctor will come to answer them. When you turn in your exam, you may be required to show ID. If you forgot to bring your ID, talk to an exam proctor immediately. We wish you the best of luck. Date Scores: [For instructor use only] Question 1 4 pts Question 2 20 pts Question 3 6 pts Question 4 6 pts Question 5 6 pts Question 6 10 pts Question 7 10 pts Total: 62 pts

CIS 110 Midterm Summer 2017 Page 1 1.) Miscellaneous (5 points) 1.1) (1 point) The Easy One: Check that your exam has all 9 pages (excluding the cover sheet, which is no numbered). Write your name, recitation number, and PennKey (username) on the front of the exam. Sign the certification that you comply with the Penn Academic Integrity Code. 1.2) (2 points) In the space provided, write code to draw the figure pictured in the window to the right (you can assume the square is half as wide as the window it is in. You do not have to draw the window, only the shapes. PennDraw.line(0.0, 1.0, 1.0, 0.0); PennDraw.filledRectangle(0.25, 0.25, 0.25, 0.25); 1.3) (1 point) How many times would the following print HelloWorld? int i = 17; while (i >= 0) { i /= 2; if (i % 2 == 0) { System.out.println("Hello World"); a) 0 d) 6 b) 1 e) Infinite (infinite loop) c) 5 f) 0, but with an infinite loop Note: while f was the intended answer, we accepted 0 because there were unfixed typos on the original exam that would have prevented compilation.

CIS 110 Midterm Summer 2017 Page 2 2.) Operators and Expressions (20 points) 1 point for each blank For each code fragment, (a) fill in the most appropriate word in the 1st column(if there are multiple blanks, all blanks are the same word) and (b) give the value that z contains after the code has been executed in the 2nd column. If the code would result in an error, write ERROR in the 1st column and give the reason for the error in the 2nd column (you do not need to write the exact error message, just a general explanation). The first two problems have been completed for you. DO NOT WRITE WHAT PRINTS. ONLY THE TYPE IN THE BLANK AND THE VALUE OF Z???? z = 11; int 12 z++; int x = Hello World ; Cannot set an int???? z = x.length(); ERROR variable to a String String str = 25.0 ; int z =???.parsedouble(str); String s = Catdog ;???? z = s.charat(4); ERROR char Double.parseDouble() would return a double, so this wouldn't compile 'o'???? 'd'; int x = z[2]; z = {'a', 'b', 'c', z[2]++; double x = Math.random(); if (x > 0.5) {???? z = "TAILS"; System.out.println(z == "TAILS"); char[] ERROR {'a','b','d','d' z would be out of scope outside the if statement, code wouldn't compile???? z = 3 / 2 + 1.5 * 2 double 4.0???? [] x = new???? [4]; x[3] = 'c';???? z = x[0]; (continued on the next page) char 0 (or the null character, '/0')

CIS 110 Midterm Summer 2017 Page 3???? z = {"cat", 5, true;???? x = z; x[0] = "steve"; ERROR No data type can hold these values???? z = {"cat", "5", "true";???? x = z; x[1] = "steve"; String[] {"cat","steve","true" String x = "" + 1 + 2???? z = x.equals(3); String x = 1 + 2 + "";???? z = "1" + '2'; System.out.println(z == x); ERROR String "12" Cannot call the string equals function with an int argument. 3) Conditionals (6 points total) Fill in the blanks for the following method that takes in 3 integers and returns the smallest number. You cannot change any existing code. Note: there was confusion caused by this question, where the function was called max, but the behavior was min. Therefore, I accepted both min or max implementations. The answer below illustrates min public static double min(double a, double b, double c) { if (b < c) { //2 points for this blank if (b < a) { //2 points blank return b; else { return a; else { if (a > c) { return c; //1 point else { Return a; //1 point

CIS 110 Midterm Summer 2017 Page 4 4) (6 points) Tracing In a failed attempt to make computer science fun, Will wrote the following function. Trace the function using the inputs below to determine the output. You are encouraged to use scratch paper to help you trace 1 2 3 4 5 6 7 8 9 10 11 12 public static int fun(int decorations, int surprise) { int party = 0; int cake = -1 * surprise; while (surprise > cake) { surprise--; for (int hats = decorations; hats > 0; hats -= 2) { party++; hats++; surprise--; return party; ONLY WRITE WHAT RETURNS IN THE BOX (1.5 points each) A) fun(1,3); 3 B) fun(2,3); 6 C) fun(4,3); 12 D) fun(12, 10); (tip: look at the relationship between input and output on the last) 120

CIS 110 Midterm Summer 2017 Page 5 5) Method Writing Moderate (6 points) You will be writing an int method that takes in an integer array (int[] arr) and one int number (int c). This function returns the number of times c appears in arr. You can ASSUME the following: The array has at least 1 element (is not empty) The number c could appear as few as zero times, and as many as every time. Do not write any code to address those assumptions, just assume those things are all true. public static int count(int[] arr, int c) { int count = 0; for(int i = 0; i < arr.length; i++) { if (arr[i] == c) { count++; return count;

CIS 110 Midterm Summer 2017 Page 6 6) Debugging (10 points) The function below is supposed to give the nth letter of the alphabet, where 0 is 'A', 1 is 'B', and so on. In the code below, there are 6 bugs that prevent the code from COMPILING (only worry about compile time errors, not logic bugs). Identify these bugs by the LINE number, then suggest a fix to the line of code. Example Bug 1: Line 1 no return type on function header. Should be "public static char getnthletter(int n) That's 1 down, 5 more for you to find! Note that you are only allowed to edit the line of code you say would cause a compile time error. You are not allowed to change any other lines of code; There were actually 7 bugs here, people got full credit if they found at least 6. The bugs are highlighted in red 1 public static getnthletter (int n) { 2 char ch = "A"; //should be 'a' 3 //if n is less than 0 or greater than 25, return 4 / a whitespace character //you need two slashes 5 if (n < 0 or n > 25) { //should be 6 return ' ' //no semi colon 7 8 for (int counter = 0, counter < n, counter++) { //; not, 9 int newchar = ch; 10 newchar++; 11 ch = newchar; //need to typecast to (char) 12 13 return ch; 14 Here is an image of the compilable code

CIS 110 Midterm Summer 2017 Page 7 7) Method Writing Harder (10 points) An anagram is when two words have the same letters, but in a different order. For example, "binary" and "brainy" are anagrams. Is this question, you will write the method isanagram that takes in two strings and determines whether or not they are anagrams. Use an appropriate return type for what this method is asking you to do. You can assume (do not check) that all characters in the input strings are lowercase. Be careful, however, as this is harder than it first looks. Example: "need" and "eden" are anagrams, but "den" is not an anagram of either because it doesn't have two e's. Further, neither is "nedd" as while it has the same letters, it only has 1 e and 2 d's. There were a number of ways to do this, below is in my opinion the easiest. public static boolean isanagram(string a, String b) { //If the strings aren't the same length, //they cannot be anagrams if (a.length()!= b.length) { return false; //get letter counts of both strings int[] alettercounts = new int[26]; int[] blettercounts = new int[26]; //only need one loop since both strings have //same number of letters for (int i = 0; i < a.length; i++) { char achar = a.charat(i); char bchar = b.charat(i); //'a' 'a' is 0, 'b' 'a' is 1... //'y' 'a' is 24 'z' 'a' is 25 //we use this to keep track of letter counts alettercounts[achar 'a']++; blettercounts[bchar 'a']++; //if any letter counts don't match //return false. Otherwise they are anagrams for (int i = 0; i < alettercounts.length; i++) { if (alettercounts[i]!= blettercounts[b]) { return false; //if you made it this far, they are anagrams return true;

CIS 110 Midterm Summer 2017 Page 8 Extra Space for Answers DO NOT RIP THIS PAGE OFF. ANY WRITING ON THIS PAGE CAN BE GRADED

CIS 110 Midterm Summer 2017 Page 9 Scratch Paper YOU MAY USE THIS PAGE FOR SCRATCH WORK, BUT NOTHING ON IT WILL BE GRADED