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

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

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

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

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

CIS Introduction to Computer Programming. 5 October 2012 Midterm

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

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

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

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

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

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

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

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

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

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

CIS 371 Spring 2015 Computer Organization and Design 7 May 2015 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 Introduction to Computer Programming Spring Exam 2

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

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

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

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

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

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

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):

COS 126 Midterm 1 Written Exam Fall 2011

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

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

Question: Total Points: Score:

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 2012

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

Question: Total Points: Score:

CS 1301 Exam 1 Fall 2010

COS 126 General Computer Science Fall Written Exam 1

CSE 131 Introduction to Computer Science Fall Exam I

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!

Final Exam. COMP Summer I June 26, points

CSE 131 Introduction to Computer Science Fall Exam I

CS 1301 Exam 1 Fall 2010

CSE 131 Introduction to Computer Science Fall Exam II

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

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

Question: Total Points: Score:

CSE 131 Introduction to Computer Science Fall Exam I

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

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

CS170 Introduction to Computer Science Midterm 2

Conditionals, Loops, and Style

Lecture 5: Methods CS2301

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

EE 312 Fall 2017 Midterm 1 October 12, 2017

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

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

Introduction to Computer Science Midterm 3 Fall, Points

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

COS 126 General Computer Science Spring Written Exam 1

Final Exam COMP Fall 2004 Dec 16, 2004

Question: Total Points: Score:

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

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

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

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

EXAMINATION INSTRUCTIONS

CS 61B: Midterm Exam I

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

AP CS Unit 3: Control Structures Notes

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

APCS Semester #1 Final Exam Practice Problems

Instructor: Yu Wang 11/16/2012

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1 Answer Key

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

COS 126 Midterm 1 Written Exam Spring 2015

Problem Pts Score Grader Problem Pts Score Grader

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

Exam Percentage: / 55 = %

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

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

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

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CS 2316 Exam 4 Fall 2012

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

Transcription:

Name: CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Recitation # (e.g., 201): Pennkey (e.g., eeaton): 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 110 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. Proctors have additional scratch paper if you need more than that. 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 any color(s) pen or pencil except red or pink 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. Good luck! Scores: [For instructor use only] Question 1 1 pts Question 2 8 pts Question 3 12 pts Question 4 15 pts Question 5 14 pts Question 6 25 pts Total: 75 pts

CIS 110 Fall 2016 Midterm Score: Page: 1 1.) The Easy One (1 point total) Check to make certain that your exam has all 5 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. 2.) Value Judgments (8 points total) Fill in the data type and final value of the variable a. (Assume a is always declared with the most appropriate data type.) Write CE as the data type if the statements will cause compiler error, or RE if they will cause a run-time error. Give the reason for the error in the third column, but don t worry about giving the precise error message as Java would print it. The first row has been filled in for you. Type of a Value of a/error explanation a = 9; a++; int 10 int x = 100; a = x.length; int x = 5; a = x / 2; int x = 1; int y = 1; a = (x = y); String a = "CIS"; a += 1 + 1 + 0; a = Integer.parseInt('2'); String s = "Will Adam Brown?"; a = s.charat(16); a = 'a' < 'b'; double x = 2.0; a = x / 0;

CIS 110 Fall 2016 Midterm Score: Page: 2 3.) A Bug s Life (12 points total) The following function is supposed to calculate the highest possible sum of any two entries in an array of positive integers. For example, given the array {4, 5, 3, 2, 8, it should return 13 (the sum 5 + 8). Unfortunately it is infested with bugs. Write the corrected code in the space below. Make sure your corrected function is reasonably well indented, is syntactically correct, and is the same number of lines as the buggy version because we will be grading your answer line by line. (You may place open curly braces on their own line, if you prefer, and you may add blank lines. But do not make any other changes to the total number of lines.) 1. public static int highestsum(int[] arr) { 2. int maxsum = 0; 3. for (i = 0; i < arr.length; i++) { 4. for (int j = i + 1; j < < arr.length(); i++) { 5. int sum == arr[i] + arrj[j]; 6. if (sum < maxsum) { 7. int maxsum = sum 8. 9. 10. return maxsum; 11. 12.

CIS 110 Fall 2016 Midterm Score: Page: 3 4.) I Scream, Ice Cream (15 points total) Study the following program, then answer the questions. public class IScreamIceCream { public static void toppings(int y) { if (y < 2) return; System.out.println("sprinkles"); toppings(y - 1); public static String flavor(string f, String p, int x) { if (x % 2 == 0) { System.out.println(x + " scoop " + f); if (x % 4 == 0) { toppings(x - 1); return flavor(p, f, x + 2); else { return flavor(f, p, x - 1); else { System.out.println(x + " scoop " + p); if (x <= 2) return "Coming right up!"; else return flavor(f, p, x - 2); public static void main(string[] args) { int num = Integer.parseInt(args[0]); System.out.println(flavor("vanilla", "chocolate", num)); Give the exact output of each of the two following commands: java IScreamIceCream 3 java IScreamIceCream 4

CIS 110 Fall 2016 Midterm Score: Page: 4 5.) Drop It Like It s Hot (14 points total) The following function is supposed to compute your average homework percentage according to the CIS 110 homework policy: given an array of homework percentages between 0 and 100%, it drops the lowest score as long as there are at least two scores in the array and the lowest score is at least 30%, then returns the average. Unfortunately, the TAs who were writing the function ran off screaming after the limo of Snoop Dogg and Pharrell Williams before finishing the code. Fill in the blanks to complete the function. 1. public static double homeworkgrade(double[] scores) { 2. if (scores == ) return 0; // error checking 3. int numscores = ; 4. if (numscores == ) return 0; // error checking 5. double lowestscore = ; 6. double sum = 0.0; 7. for ( ; i < numscores; i++) { 8. if ( < lowestscore) { 9. = scores[i]; 10. 11. sum += ; 12. 13. if ((lowestscore < 30) ( )) { 14. return ; 15. 16. return ; 17.

CIS 110 Fall 2016 Midterm Score: Page: 5 6.) Get it on the Green (25 points total) An enterprising alum of Horton s School of Funny Business with a poor understanding of statistics is planning a weighted roulette ball that is more likely to land on green spaces for his upcoming gambling and golf resort. He believes that the function described below will properly verify that the ball will land on green more often than a normal ball would. Since he s offered to comp you a week in a suite in his new casino, you oblige. Write a function roulette that takes an integer argument n, returns a string, and implements the following behavior: Use Math.random() to simulate the outcome of spinning a roulette wheel with 18 red spaces, 18 black spaces, and 2 green spaces n times, and count the number of times the ball lands in a green space. The ball is twice is likely to land in any given green space than in any given red or black space because of the way it is weighted (which means there is a 1-in-10 chance the ball will land on green); If the ball lands on a green space more often than an unweighted ball is expected to over the course of the simulations, return, "Good to go!". (An unweighted ball is equally likely to land in any of the squares, so it should land on green about 1/19th of the time.) Otherwise return the number of times the ball landed on green, represented as a string. Do not write the class statement, just the function that would be contained within the class. Your program must be syntactically correct, and you must make a reasonable attempt to indent your code. You do not need to write comments, but you are allowed to if that makes it easier for you. You are also welcome to use more than one color of pen/pencil (but not red), if that help you.