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

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

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

CIS 110 Introduction to Computer Programming 8 October 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 Introduction to Computer Programming. 5 October 2012 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 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam

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

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

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

CIS Introduction to Computer Programming Spring Exam 1

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

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

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

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

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. February 29, 2012 Midterm

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

CIS Introduction to Computer Programming Spring Exam 2

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

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

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

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

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

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key for review problems

Practice Midterm 1. Problem Points Score TOTAL 50

Exam Percentage: / 55 = %

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key

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

Practice Midterm 1 Answer Key

Final Exam. COMP Summer I June 26, points

STUDENT LESSON A12 Iterations

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

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

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

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

CS 2316 Exam 1 Spring 2013

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

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

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!

Instructor: Yu Wang 11/16/2012

CSE 1223: Exam II Autumn 2016

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

COS 126 General Computer Science Spring Written Exam 1

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

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

PRACTICE MIDTERM EXAM #2

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CS 2316 Exam 1 Spring 2014

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

CS 1301 Exam 1 Spring 2014

CS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017

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

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

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

EE 312 Fall 2017 Midterm 1 October 12, 2017

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

Spring Semester 10 Exam #1 Dr. Dillon. (02/18)

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

Without fully opening the exam, check that you have pages 1 through 11.

CSE 131 Introduction to Computer Science Fall Exam II

CS 1301 Exam 3 Spring 2014

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Question Points Score

Repetition. We might start out with the following program that draws only the left most object.

CS Name : Grading TA:

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

Lecture 13: Two- Dimensional Arrays

CS100J February 13, 2001

CS100J November 20, 2001

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

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

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

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

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

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

University of Maryland College Park Dept of Computer Science

Question: Total Points: Score:

Examination Questions Midterm 1

Question: Total Points: Score:

CS 1301 Exam 1 Spring 2014

PRACTICE MIDTERM EXAM #1

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

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

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS 1301 Exam 1 Fall 2010

Question: Total Points: Score:

Transcription:

CIS 110 Introduction to Computer Programming Summer 2016 Midterm Name: Recitation # (e.g., 201): 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 60 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. If a page becomes loose, re - attach it with the provided staplers. Staple 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. Clearly indicate on the question page where the graders can find the remainder of your work (e.g., back of page or on extra sheet ). 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 9 pts Question 2 12 pts Question 3 10 pts Question 4 9 pts Question 5 15 pts Total: 55 pts

CIS 110 Midterm Spring 2014 SCORE Page 1 1.) MISCELLANEOUS (9 pts total) 1.1) (1 point) The Easy One: Check that your exam has all 10 pages (excluding the cover sheet). 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, draw what the result of running the following code fragment in PennDraw would be: PennDraw.drawRectangle(.5,.25,.5,.25); PennDraw.drawLine(1.5,.5,1.0,1.0); Note: color doesn t matter. Use any writing utensil Only the rectangle was in the frame. The line is out of frame and therefore not drawn (no points were lost if you the line outside the frame) 1.3) (2 points) How many times would this code fragment print the text Hello World? for (int i = 11/2; i >= 0; i -= 5;) { System.out.println("Hello World"); A. Zero (0) B. One (1) C. Two (2) D. None, this is invalid Java code Note: you received 1 point if you selected 2. However, the semicolon after the statement highlighted in red is an error. 1.5) (2 points) int x = 3+(int)(3.99)*2; What does x equal after this statement? A. Nine (9) B. Eleven (11) C. Twelve (12) D. Fourteen (14)

CIS 110 Midterm Spring 2014 SCORE Page 2 1.4) (2 points) The result of evaluating 4 / 3 + 5 * 2 / 3 = 4 2.) OPERATORS AND EXPRESSIONS (12 points total) For each code fragment, (a) fill in the most appropriate data type in the 1st column 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.???? z = 11; z++; int 12 int x = Hello World ;???? z = x.length; ERROR Int X cannot be set to a string int x = 5; double 2.0 int y = 3;???? z = x / y * 2.0; char a = 97;???? z = a++; char (int was accepted) 98, or b (97 as a char equals a. Either answer was acceptable) int[] x = { 2, 1, 3, 0 ;???? z = x; x[x[0]++]++; int[] {3,1,4,0 This question was thrown out because this relied on understanding the order ++ is executed in relative to other operations. We didn t cover that in class, so for fairness, no one lost points here.

CIS 110 Midterm Spring 2014 SCORE Page 3???? z = 5.5; double 1.5 z %= 4.0;???? z == true; ERROR There is nothing you can put in the blank (certainly not boolean) that will make this statement work. String str = Midterm ;???? z = str + 5; String Midterm5 3.) CONDITIONALS AND LOOPS (10 points total) The code fragment below contains four blanks, labeled A, B, C, D, and E. Fill in the blanks to make the chessboard image shown on the right. Note that it must match the image as much as possible. Pay special attention to the corner tiles: for( A { for( B { if ((i+j)%2 C 0){ PennDraw.setPenColor(PennDraw.BLACK); else{ PennDraw.setPenColor(PennDraw.WHITE); double xcenter = _D ; double ycenter = E ; PennDraw.filledRectangle(xCenter, ycenter, 0.5/8, 0.5/8); Note that there were multiple acceptable answers here. This is only 1 such answer. Blank A: (int i =0; i<8; i++) Blank B: (int j =0; j<8; j++) Blank C: == Blank D: (i+0.5)/8.0 Blank E: (i+0.5)/8.0

CIS 110 Midterm Spring 2014 SCORE Page 4 4) Tracing a Loop (9 points) Consider the follow code fragment that contains a nested loop. Use this code fragment to answer the following questions. The next page is blank and may be used for notes. int[] x = {0,0,0,0,0,0,0,0; for (int i=1; i<x.length; i*=2){ //outer loop for (int j=i; j<x.length; j++){ //inner loop x[i]++; x[j]++; //Print array for(int j=0; j<x.length; j++){ System.out.print(x[j]+","); System.out.println(); System.out.println( exit ); How many times will the outer loop execute? Write what will be printed line by line from this code fragment. Remember that System.out.println(); prints a line break, meaning the next piece of text will appear on the next line. [line1] 0,8,1,1,1,1,1,1, [line2] 0,8,8,2,2,2,2,2, [line3] 0,8,8,2,7,3,3,3, [line4] exit [line5] [line6] [line7]

CIS 110 Midterm Spring 2014 SCORE Page 5 5.) 2D Arrays + Testing (15 points) You are tasked with writing a function using test driven development that transposes a matrix, represented as a 2D integer array. An example of transposing a matrix is below: Your function should return a new 2D integer array, without doing anything that changes the values of the original input array. Your function should check the following: 1) That the input array isn t empty. 2) That every row in the input array has the same number of columns If either of these conditions fail, then you should print an error and return an empty array. 5.1) Method declaration (2 points) Write the method declaration here. Circle the parts of the method declaration that make up the method signature: (note: underlined sections are part of the signature) public static int[][] transpose ( int[][] inputarray) 5.2) Tests (3 points) Write simple tests with the goal of testing both a normal execution, and abnormal execution below. Do not just copy the example above. Your goal is to have coverage as discussed in class. You may write your input and output matrices as they are in the picture above. You do not have to write them as they would appear in Java. If you need more space, use the blank page AFTER 6.3 (page 8) Tests in this case were evaluated on two things: example input and expected output. For example, an empty input matrix should generate expect output of an empty matrix. An example of proper execution can be shown above in the picture given for this assignment. For coverage, we were looking for 1 input of ideal execution, 1 input of an empty input matrix, and 1 input of an unequal rows array, as well as the correct expected output for those inputs.

CIS 110 Midterm Spring 2014 SCORE Page 6 5.3) (10 points) Write the code of the function on this page. You may use the next blank page as needed. DO NOT PRINT the new array. Rather your function should return the array. public static int[][] transposematrix(int[][] matrix){ if ((matrix.length > 0) && (matrix[0].length > 0)){ //matrix isn't empty int firstrowlength = matrix[0].length; //get first row length //this is to ensure rows are all equal length int[][] transpose = new int[matrix[0].length][matrix.length]; //create return matrix for(int i=0; i<matrix.length; i++){ //loop throw columns if(matrix[i].length!= firstrowlength){ //row isn't the same size as expected System.out.println("Unequal row lengths"); return new int[0][0]; //return empty matrix //row is equal length for(int j=0; j<matrix[0].length; j++){ transpose[j][i] = matrix[i][j]; //transpose values into return matrix return transpose; else{//matrix is empty System.out.println("Matrix is empty"); return new int[0][0]; //return empty matrix