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

Similar documents
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 Fall 2015 Introduction to Computer Programming 7 Oct 2015 Makeup Midterm Exam

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

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

CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

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

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

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. 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. 7 May 2012 Final Exam

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 Fall 2017 Final Midterm. Recitation Section# :

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

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

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

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

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

CSE 131 Introduction to Computer Science Fall Exam I

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

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

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

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!

COS 126 Midterm 1 Written Exam Fall 2012

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

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

CS 1301 Exam 1 Fall 2010

CSE 131 Introduction to Computer Science Fall Exam I

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

AP CS Unit 3: Control Structures Notes

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

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

Practice Midterm 1 Answer Key

Conditionals, Loops, and Style

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

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

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

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

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

COS 126 General Computer Science Fall Written Exam 1

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Topics. Chapter 5. Equality Operators

Exam Percentage: / 55 = %

CONDITIONAL EXECUTION

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

CS 177 Spring 2009 Exam I

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

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

CS143 Final Fall 2009

COS 126 General Computer Science Spring Written Exam 1

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

Introduction to Computer Science Unit 2. Notes

CS170 (005): Introduction to Computer Science Exam 2

CS 1301 Exam 1 Fall 2010

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

APCS Semester #1 Final Exam Practice Problems

Variables and data types

Final exam. CS 2110, December 15, 2016, 9:00AM

CS 2316 Exam 4 Fall 2011

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

Instructor: Yu Wang 11/16/2012

Question: Total Points: Score:

Practice Midterm 1. Problem Points Score TOTAL 50

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

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

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

CS100J November 20, 2001

CONDITIONAL EXECUTION

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

CS110: PROGRAMMING LANGUAGE I

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

Question: Total Points: Score:

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

CS3 Midterm 2 Standards and Solutions

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Question: Total Points: Score:

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

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

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

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

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

COS 126 General Computer Science Fall Exam 1

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

Final Exam. COMP Summer I June 26, points

PRACTICE MIDTERM EXAM #2

Transcription:

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name: 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 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. Have a great Fall break! Scores: [For instructor use only] Question 0 1 pts Question 1 9 pts Question 2 12 pts Question 3 10 pts Question 4 16 pts Question 5 20 pts Question 6 5 pts Total: 73 pts

CIS 110 Fall 2014 Midterm Score: Page: 1 0.) THE EASY ONE (1 point total) Check to make certain that your exam has all 9 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.) TYPES AND VALUES (9 points total) Fill in the data type and final value of the variable a. (Assume a has been declared with the 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. The first row has been filled in for you. Type of a a = 2; int 2 a = false; a = a (true &&!false); double x = 3; x--; a = x; String x = "oneten"; a = x.charat('4'); Value of a/error explanation double x = 4; a = x.pow(.5); int[] x = { 3, 1, 4, 1 ; a = x[x[0]]; String x = "oneten"; a = String.length(x); a = "1"; a = a + a; a += a; a = 3; a %= 2; int x = 15; int y = 2 * x / 2; a = x == y;

CIS 110 Fall 2014 Midterm Score: Page: 2 2.) HORTON HIRES A WHO (12 points total) The Horton School of Funny Business has hired you, a recent CIS 110 graduate, to rewrite its grade calculation software. Your first task is to write a function computelettergrades() that takes an array of percentage scores (between 0 and 100, rounded to the nearest 10th of a percent), and returns an array of letter grades corresponding to the table below. The function does not need to do any error checking. You may use any of the functions from Java s Math library. Percentage Grade 0 49.9 B- 50 59.9 B 60 69.9 B+ 70 79.9 A- 80 100 50% chance of A, 50% chance of A+ Fill in the blanks below to complete the computelettergrades() function: public static computelettergrades( ) { String[] lettergrades = ; for (int i = 0; i < ; i++) { if ( ) { lettergrades[i] = "B-"; else if ( ) { lettergrades[i] = "B"; else if ( ) { lettergrades[i] = "B+"; else if ( ) { lettergrades[i] = "A-"; else if ( ) { lettergrades[i] = "A"; else { lettergrades[i] = "A+"; ;

CIS 110 Fall 2014 Midterm Score: Page: 3 3.) DEBUGGING (10 points total) Benedict has written a program to fill an array of length args[0] with random integers from 0 to 9 (including 0 and 9), then print out the average of all even numbers in the array. But as you know from lecture, he is prone to mistakes. Find the 8 buggy lines in his program, and write the line numbers and complete, corrected lines on the next page. (Some lines may have more than one bug, but they still count as a single, buggy line.) To delete a line, write the line number and Delete line. To insert a line, write the line numbers on either side of the point where you will insert your code, and write Add line: and your line of code. The first buggy line has been corrected for you, so you have 7 more to find. 00: public class EvenAverage 01: public static void main(string[] args) { 02: int fly = Integer.parseInt(args[0]); // number of array entries 03: int[] tic; // array for random numbers 04: 05: // fill in random numbers 06: for (gnat = 0; gnat < 10; gnat++) { 07: tic[gnat] = 10 * Math.random(); 08: gnat = gnat + 1; 09: 10: 11: int louse = 0; // loop index for inspecting values 12: int spider = 0; // sum of even values 13: int centipede = 0; // number of even values 14: 15: // find sum of even values and number of even values 16: while (louse < fly) { 17: if tic[louse] % 2 = 0 { 18: spider += tic[louse]; 19: centipede++; 20: 21: 22: 23: System.out.println("Average of even numbers = " + 24: spider / centipede); 25: 26: WRITE YOUR ANSWERS ON THE NEXT PAGE

CIS 110 Fall 2014 Midterm Score: Page: 4 Write your answers in the spaces below. Debugging (Cont d) Bug 0: (Example) Line 00: public class EvenAverage { Bug 1: Bug 2: Bug 3: Bug 4: Bug 5: Bug 6: Bug 7:

CIS 110 Fall 2014 Midterm Score: Page: 5 4.) ALEXANDER THE GREAT (16 points total) Your friendly TAs Alex Brashear, Alex Kornhauser, and Alex Whitaker were recently working on a class project together. Each TA wrote one function, which he named after himself. The program works, but we re having trouble figuring out what it does. Trace through the program and record the values of a, b, and c in the order that each comment of the form /* LINE XX */ is reached. Assume the program is run with the arguments 1 1. Write your answers on the following page. The first one has been filled in for you. public class ProjectAlexander { public static int alex(boolean c, int a, double b) { c = c (a >= b); /* LINE 4 */ a = alex(a * 2,!c, b * 4); /* LINE 6 */ c = a > b; /* LINE 8 */ b = alex(a * 3, b * 5,!c); /* LINE 10 */ c =!c; /* LINE 12 */ return (int) (b / a); public static int alex(int a, boolean c, double b) { /* LINE 17 */ return (int) b + a; public static int alex(int a, double b, boolean c) { /* LINE 22 */ return (int) b - a; public static void main(string[] args) { int a = Integer.parseInt(args[0]); double b = Double.parseDouble(args[1]); boolean c = false; /* LINE 30 */ a = alex(c, a, b); /* LINE 32 */ WRITE YOUR ANSWER ON THE NEXT PAGE

CIS 110 Fall 2014 Midterm Score: Page: 6 Alexander the Great (Cont d) Write the comment line numbers and values of a, b, and c in the spaces below, in the order they are reached. Assume the program is run with the arguments 1 1. Line: 30: a = 1, b = 1.0, c = false

CIS 110 Fall 2014 Midterm Score: Page: 7 5.) CODING (20 points total) For the two code writing questions below, write only the functions. Do not write the class statement. You are welcome to write comments, but it is not required. You may use any of the Math functions (Math.sqrt(), Math.min(), Math.abs(), etc.) and any of the string functions (s.equals(), s.compareto(), etc.). 5.1) (10 points) Write a function samesign() that takes an array of integers and returns true if they are all greater than zero or all less than zero, and false otherwise. If the array is null or empty, return true. 5.2) (10 points) Write a function issorted() that uses samesign() to take an array of strings and returns true if they are sorted in alphabetical or reverse alphabetical order and every string is different. Use the compareto() function to determine alphabetical order. Otherwise return false. If the array is null or empty, return true. Assume that none of the individual strings is null. (Recall that s.compareto(t) returns a positive number if s comes after t, a negative number if it comes before t, and 0 if they are the same.)

CIS 110 Fall 2014 Midterm Score: Page: 8 6.) TWENTY QUESTIONS (5 points total) Your friend tells you she has thought of a number between 1 and 400. You would like to guess this number in the least number of tries. Each time you guess a number your friend says too high, too low or tells you that you have the right number. 6.1) (2 points) If you play this guessing game correctly then, regardless of the number your friend chooses, you can find it in less than N guesses. What is the smallest possible value of N? (a) 200 (b) 400 (c) 10 (d) 9 (e) 8 6.2) (2 points) In thirty words or less, explain how you will always find your friend s number in this many guesses. 6.3) (1 point) What is the name of the algorithm you used?

CIS 110 Fall 2014 Midterm Score: Page: 9 [ Scrap Paper: This Page Intentionally Blank ]