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

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

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

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 Summer 2014 Final. Name:

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

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

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

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

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 2017 Final. Recitation # (e.g., 201):

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

CIS Introduction to Computer Programming Spring Exam 1

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

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

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 Spring 2016 Final Exam

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

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

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

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

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

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

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

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

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

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

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

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

COS 126 General Computer Science Spring Written Exam 1

COS 126 Midterm 1 Written Exam Fall 2011

COS 126 Midterm 1 Written Exam Fall 2012

Practice Midterm 1. Problem Points Score TOTAL 50

Exam Percentage: / 55 = %

Final Exam. COMP Summer I June 26, points

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

Instructor: Yu Wang 11/16/2012

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

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

Variables One More (but not the last) Time with feeling

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

ESC101 : Fundamental of Computing

COS 126 General Computer Science Fall Written Exam 1

We will start our journey into Processing with creating static images using commands available in Processing:

Practice Midterm 1 Answer Key

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

CSE 131 Introduction to Computer Science Fall Exam II

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

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

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

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

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

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

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!

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

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

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

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

SEMESTER 1, 2011 EXAMINATIONS. CITS1200 Java Programming FAMILY NAME: GIVEN NAMES:

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

CS 101 Spring 2007 Midterm 2 Name: ID:

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

COS 126 Midterm 1 Written Exam Fall 2014!

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 1301 Exam 1 Fall 2010

COS 126 Midterm 1 Written Exam Spring 2015

Gettysburg College Department of Computer Science

CSE 1223: Exam II Autumn 2016

Model Solutions. COMP 102: Test 1. 6 April, 2016

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

COS 126 General Computer Science Fall Exam 1

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)

CS100B: Prelim 3 Solutions November 16, :30 PM 9:00 PM

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

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

CS 177 Spring 2009 Exam I

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

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

CSE 142 Su01 Final Exam Sample Solution page 1 of 7

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

A Foundation for Programming

CS Exam 2 - Spring 2010

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CONDITIONAL EXECUTION

CISC 1600, Lab 3.1: Processing

APCS Semester #1 Final Exam Practice Problems

AP CS Unit 3: Control Structures Notes

Notes from the Boards Set # 5 Page

COS 126 General Computer Science Fall Exam 1

CS170 (005): Introduction to Computer Science Exam 2

Transcription:

CIS 110 Introduction to Computer Programming Summer 2014 Midterm Name: PennKey (e.g., bhusnur4): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this examination. Signature Date 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- computational 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, reattach 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. We provide reference for 2 Processing functions in the next page. Sorry, but you are expected to know how to draw a line. We wish you the best of luck. Scores: [For instructor use only] Question 0 1 pt Question 1 8 pts Question 2 10 pts Question 3 18 pts Question 4 9 pts Question 5 10 pts Question 6 20 pts Total: 75 pts

Processing functions reference ellipse(a, b, c, d) Parameters a float: x-coordinate of the ellipse center b float: y-coordinate of the ellipse center c float: width of the ellipse d float: height of the ellipse rect(a, b, c, d) Parameters a float: x-coordinate of the rectangle top left corner b float: y-coordinate of the rectangle top left corner c float: width of the rectangle d float: height of the rectangle

0.) THE EASY ONE (1 point) Check that your exam has all x pages (excluding the cover sheet and scratch paper). Write your name on the front of the exam. Sign the certification that you comply with the Penn Academic Integrity Code. 1.) MISCELLANEOUS (8 points total) 1.1) (2 points) What would be the result of the following code fragment in a Processing setup() function? size(500, 500); fill(0, 0, 255); rect(0, 0, 500, 250); A. a window with the top half blue and the bottom half white B. a window with the bottom half blue and the top half white C. a window that is entirely blue D. a window that is entirely white 1.2) (2 points) What would the window look like as a result of the following code fragment in a Processing setup() function? size(500, 500); line(200, 250, 300, 250); line(250, 200, 250,300); ellipse(250,250, 50, 50); A. A circle divided into 4 quarters B. A circle divided into 2 halves C. Just a circle. The lines will not be visible D. Two intersecting lines. No circle 1.3) (2 points) How many circles are drawn as a result of this code fragment in a Processing setup() function? A. 7 B. 3 C. 4 D. 8 for (int i = 5; i < 40; i *= 2) { ellipse(i, i, 10, 10); } 1.4) (1 point) The result of evaluating 5 * 3 + 2 / 3 is.

2.) OPERATORS AND EXPRESSIONS (10 points total) For each code fragment in the left column, (a) fill in the most appropriate data type in the middle column and (b) give the value that z contains after the code has been executed in the right column. If the code would result in an error, write ERROR in the middle column and give the reason for the error in the right column (you do not need to write the exact error message). The first two problems have been completed for you.???? z = 11; z++; int 12 int x = 100;???? z = x.length; ERROR x doesn t have an x.length field???? w = 'a'; N/A boolean b = true;???? z = b && (4 < 5); String s = " = Perfect!"; s = 4 + 2 + s;???? z = s; int x = 5; int y = 2;???? z = x / y * 3.0; int[] a = {1, 2, -1, 0, 5};???? z = a.length + a[1]; int i = 5; int z = 6; z += i + 1; N/A

3.) CONDITIONALS, LOOPS, AND ARRAYS (14 points total) 3.1) Stripes (8 points) We want to draw the following colorful striped image in Processing. Each stripe is to be 20 pixels wide. Complete the setup() method below in order to achieve this. Remember that red is (255,0,0), green is (0,255,0) and blue is (0,0,255). Do not write 40 lines of code that draw rectangles. Elegant code will be rewarded! You may continue your code on the next page, which is blank. public void setup() { int width = 500; int height = 500; size(width, height); background(255); // write your code here

// Extra page if your code does not fit into the previous page

3.2) (10 points) In Processing, we are given two arrays as class-level variables. One of them, char[] dir, has characters for directions. The other, int[] steps, gives the number of pixels to draw in that direction. We want to draw a path, beginning from the center of the window. For instance, for these specific values char[] dir = {'r', 'd', 'l', 'u'}; //directions int[] steps = {10, 20, 30, 40}; // steps taken in pixels we would like a picture that looks like the image on the right, where from the center we draw 10 pixels to the right, then 20 pixels down, then 30 to the left, then 40 up. Complete the setup() function below to achieve this. public void setup() { float x = 100; float y = 100; size(200, 200); for (int i =0; i < dir.length; i++){

4.) TRACERY (9 points) Trace through the following code. Assume that the program is executed using the command: java Tracery 7 8 9 In the table to the right of the code, write the values of a, b, and c in the order that they would appear on the console (Interactions pane of DrJava) at each of the System.out.println() statements. You may not need to use all of the table s rows. public class Tracery { static int a = 0; static String b = ""; static String c = ""; a b c static int f1(boolean flag, String c) { if (!flag) { b = "" + a; a = f2(a, b); } else { a = f2(a, c); } System.out.println(a + " " + b + " " + c); return a; } static int f2(int b, String s) { c = s; System.out.println(a + " " + b + " " + c); return Integer.parseInt(s) + b; } } public static void main(string[] args) { a = Integer.parseInt(args[0]); b = args[1]; c = args[2]; a = f1(true, b); System.out.println(a + " " + b + " " + c); a = f1(false, b); System.out.println(a + " " + b + " " + c); }

5.) DEBUGGING (10 points) Find and correct the errors in the following program that cause behavior different to that described in its header comment. Some of the errors can be corrected by adding, removing, or rewriting a line of code or a symbol such as a semicolon. Write // before any line of code that should be removed. Write any inserted or rewritten code in the space between the lines. If you require more space, you may fill in the blanks on the next page. There are a total of 8 issues in this program. /* * This program takes a single command line argument N and simulates N * coin tosses by using random numbers. * Each time the coin shows heads you earn a dollar. * Each time the coin shows tails you lose a dollar. * After N coin tosses, the total amount you earned is printed. */ 1 public class Gambling { 2 public static void main(string[] args) { 3 int numofarguments = args.len 4 float totalamount = 0; 5 if numofarguments > 1 System.out.println("only 1 argument please"); 6 else totalamount = tosscoins(args); 7 System.out.println("amount earned is " + totalamount); 8 } 9 public static int tosscoins( n ) { 10 for (int i =1; i <= n; i++) { 11 double randomnumber = math.random(); 12 if (randomnumber > 0.5) winnings += 1; 13 else winnings -= 1; 14 } 15 } 16 }

6.) FUNCTIONS! (20 points total) 6.1) (8 points) Write the public static function that is described by the function header below, including the function declaration. You do not need to define any class. /** Function Name: occurrences * Parameters: * x an integer * arr an array of doubles * Returns: * the number of elements of arr that are within 0.5 of x. * occurrences(3,{2.5, 3.2, 1, 0.0}) -> 2 * occurrences(-1,{0, 0.5, -1.5}) -> 1 */

6.2) (12 points) Write the public static function that is described by the function header below, including the function declaration. You do not need to define any class. /** Function Name: shiftsentence * Parameters: * strarr an array of strings of length n * begin a positive integer less than n * Returns: * a shifted sentence using strings in strarr as shown in examples * Error checking: * if begin is greater than or equal to n, return * Examples: * shiftsentence({"exams", "are", "tough"}, 2) returns "tough exams are" * shiftsentence({"a", "b", "c"}, 0) returns "a b c" * shiftsentence({"hurrah", "for", "the", "red", "and", "the", "blue"}, 3) returns * "red and the blue Hurrah for the" * shiftsentence({"i", "find", "your", "lack", "of", "faith", "disturbing"}, 2) returns "your lack of faith disturbing I find" */

Scrap Paper (This page is intentionally blank)