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

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

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. 12 February 2013 Midterm

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

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 8 October 2013 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 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 Spring 2016 Midterm

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

COS 126 General Computer Science Fall Exam 1

COS 126 Midterm 1 Written Exam Spring 2015

CIS 371 Spring 2015 Computer Organization and Design 7 May 2015 Final Exam

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

CIS Introduction to Computer Programming Spring Exam 1

COS 126 Written Exam 2 (Spring 2015)

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

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

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Fall Midterm 1

11. A Computing Machine

What is TOY? An imaginary machine similar to: ! Ancient computers. ! Today's microprocessors.

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

COS 126 General Computer Science Fall Exam 1

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

CIS Introduction to Computer Programming Spring Exam 2

COS 126 Written Exam 2 Spring 18

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

Computer Architecture /

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

Lecture A2: X-TOY Programming

CIS 110 Introduction to Computer Programming Spring 2016 Final Exam

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

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

! Binary and hex. ! Box with switches and lights. ! 4,328 bits = (255 " 16) + (15 " 16) + (8) = 541 bytes! ! von Neumann architecture.

12/11/ The TOY Machine II. Data Representation. What We've Learned About TOY. What We Do Today. Adding and Subtracting Binary Numbers

5. The TOY Machine II

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

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

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

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

TOY II LINC LINC. !1 Introduction to Computer Science Sedgewick and Wayne Copyright 2007

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

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

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

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

Virtual machines. Virtual machines. Abstractions for computers. Abstractions for computers. Virtual machines

Computer Science /21/2000

Question: Total Points: Score:

APCS Semester #1 Final Exam Practice Problems

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

! Ancient computers. ! Today's microprocessors. Memory. ! Stores data and programs. ! 256 "words." (16 bits each) ! Special word for stdin / stdout.

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

CIS 110 Fall 2016 Introduction to Computer Programming 8 Dec 2016 Final Exam Answer Key

COS 126 Midterm 1 Written Exam, Fall 2009

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

C++ to assembly to machine code

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

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

Final Exam. COMP Summer I June 26, points

Computer Architecture I Midterm I

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

CS 2316 Exam 4 Fall 2011

CSE 351 Midterm - Winter 2015

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

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CS170 Introduction to Computer Science Midterm 2

COMP1917 Computing 1 Written Exam Sample Questions

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

Computer Hardware Engineering

Midterm Exam CSC February 2009

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

MIPS Functions and Instruction Formats

CS 101 Spring 2007 Midterm 2 Name: ID:

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

CSE 351 Midterm - Winter 2015 Solutions

Question: Total Points: Score:

RECITATION SECTION: YOUR CDA 3101 NUMBER:

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number:

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

CS100J February 13, 2001

CS61c MIDTERM EXAM: 3/17/99

C: How to Program. Week /Mar/05

CIS 341 Final Examination 30 April 2013

Practice Midterm 1 Answer Key

18. Machine Language. Computer Systems. COMP1917: Computing 1. Machine Language Programming. History of Computer Technology

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Fall Written Exam 1

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

University of Palestine. Mid Exam Total Grade: 100

Transcription:

CIS 110 Introduction to Computer Programming 17 December 2012 Final Exam 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 5 3 15 4 20 5 25 6 30 Total: 96

CIS 110 1 CIS 110 Exam Instructions You have 120 minutes to finish this exam. Time will begin when called by a proctor and end precisely 120 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. 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. 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. You may use additional colors when writing code if this makes it easier for you, but do not write in red. Red is 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 2 TOY Reference Card INSTRUCTION FORMATS................ Format 1: opcode d s t (0-6, A-B) Format 2: opcode d addr (7-9, C-F) ARITHMETIC and LOGICAL operations 1: add R[d] <- R[s] + R[t] 2: subtract R[d] <- R[s] - R[t] 3: and R[d] <- R[s] & R[t] 4: xor R[d] <- R[s] ^ R[t] 5: shift left R[d] <- R[s] << R[t] 6: shift right R[d] <- R[s] >> R[t] TRANSFER between registers and memory 7: load address R[d] <- addr 8: load R[d] <- mem[addr] 9: store mem[addr] <- R[d] A: load indirect R[d] <- mem[r[t]] B: store indirect mem[r[t]] <- R[d] CONTROL 0: halt halt C: branch zero if (R[d] == 0) pc <- addr D: branch positive if (R[d] > 0) pc <- addr E: jump register pc <- R[d] F: jump and link R[d] <- pc; pc <- addr Register 0 always reads 0. Loads from mem[ff] come from stdin. Stores to mem[ff] go to stdout.

CIS 110 3 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 True/False 2. (5 points) For each question below, circle the correct answer: (a) TRUE FALSE For an array arr, arr[length] will return the last item in the array. (b) TRUE FALSE Java classes cannot mix static and non-static methods and variables. (c) TRUE FALSE One array cannot contain both int and double elements. (d) TRUE FALSE (int) (6 * Math.random()) will return a random integer between 1 and 6. (e) TRUE FALSE java printoutput out.txt will redirect the output of printoutput to the file out.txt (f) TRUE FALSE The command cd.. will move to the parent directory in the terminal or command prompt. (g) TRUE FALSE 0x001A in hexadecimal is the same as 00011010 in binary. (h) TRUE FALSE In two s complement notation, a binary number has a 1 in the highest-order (most significant) bit if it is positive. (i) TRUE FALSE A constructor is the only type of function that can be overloaded. (j) TRUE FALSE In a linked list, elements do not have to be sequential in memory.

CIS 110 4 Babes in TOYland 3. (15 points) The following TOY program does something, but we ve forgotten what. All we remember is that the program reads a single value from standard input (at memory address 0x11), and writes a single value to standard output (at memory address 0x21). Answer the questions below, then remind us what the program does. You may assume that the assembly language comments are correct and that the number read from standard input is not negative. Give numeric answers below in ordinary, boring, base 10. 01: 0001 (0000 0000 0000 0001, 1) 10: 8501 R[5] <- mem[01] 11: 83FF read R[3] 12: 1455 R[4] <- R[5] + R[5] 13: 2230 R[2] <- R[3] 14: 1102 R[1] <- R[2] 15: B004 mem[r[4]] <- R[0] 16: C120 if (R[1] == 0) goto 20 17: C21D if (R[2] == 0) goto 1D 18: AA04 R[A] <- mem[r[4]] 19: 1AA3 R[A] <- R[A] + R[3] 1A: BA04 mem[r[4]] <- R[A] 1B: 2225 R[2] <- R[2] - R[5] 1C: C017 goto 17 1D: 2115 R[1] <- R[1] - R[5] 1E: 1203 R[2] <- R[3] 1F: C016 goto 16 20: 8B02 R[B] <- mem[02] 21: 9BFF write R[B] 22: 0000 halt (a) What is the value in register R[4] at memory address 0x15? (b) What value does the program print if it reads zero from standard input? (c) What value does the program print if it reads one? (d) What value does the program print if it reads five? (e) Describe, in twenty words or less, what this program does.

CIS 110 5 Unbreakable 4. (20 points) For each of the four functions below and on the next page, give an intuitive description in 20 words or less of the function s purpose. In addition, in 30 words or less state whether the function will compile and run properly in all cases and what the error(s) will be otherwise. Circle your answer. (a) public static void one(int x) { while (x!= 0) { System.out.println(x); x--; (b) public static int two(char x) { String keyboard = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < keyboard.length(); i++) if (keyboard.charat(i) == x) return i;

CIS 110 6 (c) public static int three(int[] x) { if (x == null) return 0; int sum = 0; for (int i = 0; i < x.length; i++) sum += x[i]; return sum / x.length; (d) public static void four(string[] x) { for (int i = 0; i < x.length; i++) { x[i] = "" + x[i].length(); System.out.println(x[i]);

CIS 110 7 Something or Other 5. (25 points) Consider the following program, then answer the questions on the next page: public class Other { public static int foo = 0; public class Something { private Something s1; private Something s2; private int x; public Something (int x) { if (x < 1) { s1 = null; s2 = null; else { s1 = new Something(x / 2); s2 = new Something(x / 2); this.x = x; Other.foo++; public int sum() { if (s1 == null s2 == null) return x; else return x + s1.sum() + s2.sum(); public static void main(string[] args) { Something s = new Something(Integer.parseInt(args[0])); System.out.println("sum: " + s.sum()); System.out.println("foo: " + Other.foo);

CIS 110 8 What does the program Something print when run with the following arguments? (a) % java Something 0 (b) % java Something 1 (c) % java Something 2 (d) % java Something 3 (e) % java Something 4

CIS 110 9 Know Your Node Code 6. (30 points) Consider a linked list of integer values that uses the linked list node type: public class Node { public Node next; public int value; Write a public static function remove that takes a linked list of Nodes list and an integer val as arguments, modifies list by removing all nodes with the value val, and returns the modified list. You only need to write the remove() function, not the surrounding class. (Hint 1: You do not need to create any new nodes with the new operator. Hint 2: Don t look for a clever solution, just write something that works.)

CIS 110 10 Postscript (extra paper)

CIS 110 11 Postscript (extra paper)