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

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

CIS 110 Spring 2014 Introduction to Computer Programming 12 May 2014 Final Exam Answer Key

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

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

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

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

CIS 110 Introduction to Computer Programming 20 December 2013 Final Exam. Answer Key

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

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

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

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

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

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

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

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

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

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

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

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

COS 126 Midterm 1 Written Exam Spring 2015

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 314 Exam 2 Spring 2018

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Practice Midterm 1. Problem Points Score TOTAL 50

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

Java Review: Objects

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

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

LECTURE 18. Control Flow

CIS Introduction to Computer Programming Spring Exam 2

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

Exam 1 - (20 points)

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

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

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

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

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Practice Midterm 1 Answer Key

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

1. (9 points) Recall the definition of the ListNode class: public class ListNode { int data; ListNode next; }

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

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

COS 126 General Computer Science Spring Written Exam 1

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

CSE 131S Introduction to Computer Science Summer SON Exam I

CS 177 Week 15 Recitation Slides. Review

Problem Grade Total

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

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Linked Lists. References and objects

WYSE Academic Challenge State Finals Computer Science 2007 Solution Set

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

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

CIS Introduction to Computer Programming Spring Exam 1

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature:

CS 314 Principles of Programming Languages

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

CS171 Midterm Exam. October 29, Name:

Last time s big ideas

DNHI Homework 3 Solutions List, Stacs and Queues

Certified LabVIEW Associate Developer Exam. Test Booklet

1 Inheritance (8 minutes, 9 points)

APCS Semester #1 Final Exam Practice Problems

UMBC CMSC 331 Final Exam

Name: Pennkey (eg, sweirich): CIS 120 Final Exam May 8, 2012

Sample Examination Paper Programming and Software Development

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

COP4020 Programming Languages. Control Flow Prof. Robert van Engelen

Linked Lists. Linked List vs Array vs Python List Singly Linked List Bag ADT Revisited Building Linked Lists

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

COS 126 General Computer Science Fall Exam 1

CSE 143. Lecture 7: Linked List Basics reading: 16.2

CS4215 Programming Language Implementation

Structure and Interpretation of Computer Programs

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

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

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

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

CIS 341 Final Examination 4 May 2017

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

Information Science. No. For each question, choose one correct answer and write its symbol (A E) in the box.

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

PROGRAMMING FUNDAMENTALS

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Object-oriented Programming and Software Engineering CITS1001. Multiple-choice Mid-semester Test

Project 1. due date Sunday July 8, 2018, 12:00 noon

CSE 114 Computer Science I

Building Java Programs

CS 307 Midterm 2 Spring 2011

Chapter 4 Introduction to Control Statements

CSCE 206: Structured Programming in C++

CSC207 Quiz 1 Solutions Monday 6 February 2017, 12:15 PM. 1. (A) (B) (C) (D) (E) 7. Nothing, does not run true false

CSE 113 A. Announcements - Lab

Recursion. COMS W1007 Introduction to Computer Science. Christopher Conway 26 June 2003

Transcription:

CIS 110 1 CIS 110 Spring 2013 Final Exam, 29 April 2013, Answer Key Miscellaneous 0. (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 Multiple Choice 1. (10 points) For each of the following questions, circle the correct answer: (a) What happens if you try to access a private variable from outside the class in which it is declared? i. The program runs normally. ii. The program runs, but treats the variable as having the value 0 or null. iii. The program runs, but the statement accessing the private variable is ignored. iv. The program runs, but behaves unpredictably. v. The program compiles, but a run-time error occurs. vi. The program does not compile. (b) 5 / 2 * Math.random() generates a random number between... i. 0 and 2.5. ii. 0 and 2. iii. 2 and 5. iv. 2.5 and 5. v. 2 and. vi. 2.5 and.

CIS 110 2 (c) What does the following function return? i. x ii. y iii. z Multiple Choice (Cont d) public static boolean foo(boolean x, boolean y, boolean z) { if (x && y) return!x z; else return (x && y) z; iv. x && y v. true vi. true if either x and y are both true or z is true, and false otherwise (d) The tostring() method of an object should do which of the following? i. Print the object to standard output in a sensible way. ii. Return a sensible String representation of the object. iii. Print the object to standard output in a sensible way and return that output as a String. iv. Whatever the object s designer wants it to do. v. Read in the contents of the object from standard input. vi. None of the above (e) Which of the following expressions computes the length of a string s? i. s.length ii. s.length() iii. String.s.length iv. String.s.length() v. String.length vi. String.length()

CIS 110 3 Easy as ABC 2. (12 points) For each question below, what will the code snippet print out? If there is an error, your answer should show that you know what causes the error, but you do not need to reproduce Java s error message exactly. Put a box around your answer so we can distinguish it from your scratch work. (a) B b = new B(7, "bad"); A a = new A(b); System.out.println(a.get()); Exception in thread "main" java.lang.nullpointerexception at A.get(...)... (b) B b = new B(7, "bad"); A a = new A(b, b.c); System.out.println(a.get()); bad bad (c) B b = new B(7, "bad"); A a = new A(b, b.c); System.out.println(a.c); bad (d) C b = new C(); System.out.println(b.c); Exception in thread "main" java.lang.nullpointerexception at C.<init>(...)...

CIS 110 4 Toying With TOY 3. (20 points) Consider the following TOY program, then answer the questions on the following page. You may assume that all assembly comments are correct. 10: 81FF read R[1] 11: 82FF read R[2] 12: 7400 R[4] <- 0000 13: 7501 R[5] <- 0001 14: 7602 R[6] <- 0002 15: 2321 R[3] <- R[2] - R[1] 16: D31B if (R[3] > 0) goto 1B 17: 1445 R[4] <- R[4] + R[5] 18: C31C if (R[3] == 0) goto 1C 19: 2112 R[1] <- R[1] - R[2] 1A: C015 if (R[0] == 0) goto 15 1B: 2323 R[3] <- R[2] - R[3] 1C: 94FF write R[4] 1D: C622 if (R[6] == 0) goto 22 1E: 1444 R[4] <- R[4] + R[4] 1F: 2665 R[6] <- R[6] - R[5] 20: 1333 R[3] <- R[3] + R[3] 21: C01D if (R[0] == 0) goto 1D 22: C226 if (R[2] == 0) goto 26 23: 1646 R[6] <- R[4] + R[6] 24: 2225 R[2] <- R[2] - R[5] 25: C022 if (R[0] == 0) goto 22 26: 1563 R[5] <- R[6] + R[3] 27: 95FF write R[5] 28: 0000 halt (a) For each pair of numbers below, what will the program write to standard output? Write your answers in decimal (base 10) and put a box around it. i. 1 and 1 1 and 4 ii. 2 and 1 2 and 8 iii. 1 and 2 0 and 4 iv. 0 and 1 0 and 0 v. 0 and 0 1 and 0 vi. 1 and 0 infinite loop (we also accepted the answer nothing ) (b) In simple formulas, what values are outputted if the first input is larger than the second? a / b and 4 * a (c) In simple formulas, what values are outputted if the first input is smaller than the second? 0 and 4 * a

CIS 110 5 The Tree of Knowledge 4. (25 points) (a) If the following code is executed: int[] vals = { 3, 7, 8, 2, 9, 1, 6, 4 ; Knowledge k = new Knowledge(); k.apple = 5; for (int i = 0; i < vals.length; i++) k.insert(vals[i]); i. What will k.a() print? 9 8 7 6 5 4 3 2 1 ii. What will k.b() print? 5 7 8 9 6 3 4 2 1 iii. What will k.c() print? 1 2 4 3 6 9 8 7 5 (b) For each of the outputs below, say which of A(), B(), and/or C() could have produced it. For each answer, give an order in which you could insert the elements to produce the output. Write none if none of them could have produced it. Put a box around your answer so we can distinguish it from your scratch work. Assume you create a single Knowledge object, then progressively add values using the insert() method, just like the code snippet in part (a). i. 1 2 3 4 5 B() (insert e.g. 1, 2, 3, 4, 5) or C() (insert e.g. 5, 4, 3, 2, 1) ii. 5 4 3 2 1 A() (insert in any order), B() (insert e.g. 5, 4, 3, 2, 1), or C() (insert e.g. 1, 2, 3, 4, 5) iii. 2 3 4 3 B() (insert e.g. 2, 3, 4, 3), or C() (insert e.g. 3, 4, 2, 3)

CIS 110 6 Leave and Let Leave 5. (30 points) (a) Write a recursive version of interleave(). public static Leave interleave(leave a, Leave b) { if (a == null) return b; // base case a.next = interleave(b, a.next); // this is clever; draw a picture return a; // all done! (b) Write an iterative version of interleave(). public static Leave interleave(leave a, Leave b) { if (a == null) return b; // special case for a is null Leave head = a, tail = a; // interleaved lists starts at first node of a a = a.next; // advance a because we already took its first node // as long as both lists have at least one more element while (a!= null && b!= null) { tail.next = b; // append first node of b to interleaved list b = b.next; // advance to next node of b tail.next.next = a; // append first node of a to interleaved list a = a.next; // advance to next node of a tail = tail.next.next; // update tail of list (we just added two nodes) if (b == null) tail.next = a; // append anything left at end of a or b else tail.next = b; return head; // return interleaved list -- or -- public static Leave interleave(leave a, Leave b) { if (a == null) return b; // special case for a is null Leave head = a, tail = a; // interleaved lists starts at first node of a for (a = a.next; b!= null; tail = tail.next) { tail.next = b; // append first node of b to interleaved list // swap a and remaining nodes of b Leave tmp = a; a = b.next; b = tmp; tail.next = a; // append rest of a to the end of the interelaved list return head; // return the interleaved list