CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

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. 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 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam

CIS 110 Introduction to Computer Programming Spring 2016 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 Summer 2016 Midterm. Recitation # (e.g., 201):

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

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

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 Fall 2017 Midterm. Recitation ROOM :

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

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

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

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

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

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

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

CIS Introduction to Computer Programming Spring Exam 2

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

COS 126 Midterm 1 Written Exam Fall 2011

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

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

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

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

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

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

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

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

Question: Total Points: Score:

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

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

AP CS Unit 3: Control Structures Notes

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

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

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

Final Exam. COMP Summer I June 26, points

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

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

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!

APCS Semester #1 Final Exam Practice Problems

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

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

Practice Midterm 1 Answer Key

Introduction to Computer Science Unit 2. Notes

Csci 102: Sample Exam

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

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

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Practice Midterm 1. Problem Points Score TOTAL 50

EE 312 Fall 2017 Midterm 1 October 12, 2017

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

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

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

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

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

NATIONAL UNIVERSITY OF SINGAPORE

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

AP Computer Science A Summer Assignment 2017

Final Examination CS 125 Introduction to Computer Science Fall Hours

Question: Total Points: Score:

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

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

COS 126 Midterm 1 Written Exam Spring 2015

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2012

Exam Percentage: / 55 = %

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

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CONDITIONAL EXECUTION

COS 126 Midterm 1 Written Exam Fall 2014!

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

CSE 1223: Exam II Autumn 2016

CONDITIONAL EXECUTION

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

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

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

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2012

COS 126 General Computer Science Fall Exam 1

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CMSC 331 Second Midterm Exam

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

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CMSC 330 Exam #2 Fall 2008

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

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

Transcription:

CIS 110-001 Introduction to Computer Programming 5 October 2012 Midterm Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this examination. Signature Date Scores: 1 1 2 4 3 7 4 8 5 15 6 15 Total: 50

CIS 110-001 1 CIS 110 Exam Instructions You have 45 minutes to finish this exam. Time will begin when called by a proctor and end precisely 45 minutes after that time. If you continue writing after the time is called, you will receive a zero for the exam. Make sure your phone is turned off before the exam starts. If it vibrates or rings during the exam, you will receive a substantial penalty. Because this exam is given twice, back-to-back, a few extra rules apply. Failure to comply may result in a substantial point deduction on your exam. You may not leave the exam room early. Food and drink are strictly forbidden, including water and gum. 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 building. You must leave the exam room and building quickly and quietly through the designated exit. You may not discuss the exam on the way out. This exam is closed-book, closed-notes, and closed-computational devices. Except where noted, code included in the questions is correct and you may use it as a reference for Java syntax. This exam is long. If you get stuck part way through a problem, it may be to your advantage to go on to another problem and come back later if you have time. All code must be written out as normal, including all curly braces and semicolons, unless the question states otherwise. Do not separate the pages of the exam. If a page becomes loose, write your name on it and use the provided staplers to reattach the sheet when you turn in your exam so that we don t lose it. We reserve the right not to grade any answers on loose sheets of paper. Turn in all scratch paper that you use during the exam. Do not take any sheets of paper with you or leave them behind. If you require extra paper, please use the backs of the exam pages or the extra sheet(s) of paper 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 ). Staple an extra sheets you use to the back of your exam when you turn it in using the provided staplers. Use a pencil, or blue or black pen to complete the exam. All other colors are reserved for grading. If you do not have an appropriate writing utensil, raise your hand, and we will give you a pencil. If you have any questions, raise your hand and an exam 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, have fun!

CIS 110-001 2 Miscellaneous 1. (1 points) (a) Write your name, recitation number, and PennKey (username) on the front of the exam. (b) Sign the certification that you comply with the Penn Academic Integrity Code Money, money, money, money, money... 2. (4 points) Consider the following recursive function: public static double compoundinterest(double balance, int months, double rate) { if (months <= 0) return balance; balance = balance * rate; return compoundinterest(balance, months - 1, rate); (a) Is this function tail recursive (circle your answer)? YES NO MAYBE (b) How many times will compoundinterest(0, 12, 1.05) call itself recursively? (c) What value will compoundinterest(0, 12, 1.05) return? (d) Will the following non-recursive function produce the same or different results from the recursive function above? Circle your answer. SAME DIFFERENT public static double iterativeinterest(double balance, int months, double rate) { for (int i = months; i >= 0; i--) balance = balance * rate; return balance;

CIS 110-001 3 Cabin 3. (7 points) Given the following class, answer the questions below and on the next page: public class Fever { public static int restless(int[] arr) { int sum = 0; for (int i = 0; i < arr.length; i++) sum = sum + arr[i]; return sum / arr.length; public static void main(string[] args) { int[] intargs = new int[args.length]; for (int i = 0; i < args.length; i++) intargs[i] = Integer.parseInt(args[i]); System.out.println(restless(intArgs)); (a) Circle the statements below that are true i. will not compile because the for loops do not have curly braces; ii. will not compile because restless() is called inside System.out.println; iii. intargs[] is args[] converted into an integer array; iv. may crash with an ArrayIndexOutOfBounds error when run; v. does not print anything because the intargs[] array is different from the arr[] array ; vi. prints the approximate average of the command line arguments.

CIS 110-001 4 (b) Assuming that any errors you identified above are corrected, what will the program print out in each of the following cases? We will consider your answer correct as long as it shows you understand what the program will print out. i. % java Fever ii. % java Fever 1.3 2.5 7.1 iii. % java Fever 1 2 5 iv. % java Fever hello world

CIS 110-001 5 Find the Bugs 4. (8 points) Identify eight errors in the following program that prevent it from compiling or from running and show how to correct them. Write your answers in the space provided on the next page. The line numbers are for your convenience and are not part of the program. 1: public class Foo() { 2: public static int main(string[] args) { 3: int rows = args[0]; 4: drawsomething(rows); 5: double hyp = computesomething(rows); 6: System.out.println("length(hypotenuse)" = hyp); 7: 8: public static void drawsomething(int rows) { 9: for (i = 0; i < rows; i++) { 10: for (j = 0; j < i + 1; j = j + 1) 11: System.out.print("*"); 12: System.out.println(); 13: 14: 15: public static double computesomething(int leg) { 16: int sqrt2 = Math.sqrt(2); 17: return sqrt2 * leg; 18: 19:

CIS 110-001 6 Bug 1: Bug 2: Bug 3: Bug 4: Bug 5: Bug 6: Bug 7: Bug 8:

CIS 110-001 7 Partial Sums 5. (15 points) The median, or middle value, of a list of numbers is extremely useful in a variety of computer and statistical algorithms. But it is notoriously slow to compute relative to the number of times it needs to be computed. Often, it is better to settle for an approximation of the median than to calculate it exactly. One of the simplest approximations is to pick three random elements, and calculate the median of those three. Write a function threemedian that takes a single argument N, reads in N doubles from standard input using StdIn.readDouble(), and returns the median of three randomly chosen elements. Assume that N is always at least three, and that all calls to StdIn.readDouble() succeed without error. Use Math.random() to pick the three random elements (recall that Math.random() returns a random number between 0 and 1, but never exactly 1). Do not write the code for the class that contains threemedian, only write the function itself. You do not need to comment your code.

CIS 110-001 8 Tracery 6. (15 points) For each of the labeled points in the code fragment below, identify each of the assertions in the table as being sometimes, always, or never true. Assume that bar is only called from within foo, and that the values of all ints stay within the valid range for integers (i.e. no value will grow so large that it will wrap around become negative, or vice cersa). Abreviate sometimes with S, always with A, and never with N. public static void foo(int x, int y, int z) { if (x > y && y <= 0) y = Math.abs(y - x) + 1; else if (x < y) z = Math.abs(z) + 1; else x = y - 1; A // Point A x > 0 x > y z > y if (z > x) { z = x; x = y * y + 2; // Point B else { z = x; z = bar(y, Math.abs(x), z * z); // Point C B C D E if (y == x) y--; // Point D public static int bar(int z, int x, int y) { for (int i = 0; i < x; i++) y = y - x; // Point E return z + y;

CIS 110-001 9 Postscript (extra paper)

CIS 110-001 10 Postscript (extra paper)