COS 126 Midterm 1 Written Exam, Fall 2009

Similar documents
COS 126 Midterm 1 Written Exam Fall 2011

COS 126 General Computer Science Fall Written Exam 1

COS 126 General Computer Science Fall Exam 1

COS 126 General Computer Science Spring Written Exam 1

COS 126 Midterm 1 Written Exam Fall 2012

COS 126 Midterm 1 Written Exam Spring 2015

COS 126 General Computer Science Fall Exam 1

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Fall Midterm 1

COS 126 Midterm 1 Written Exam Fall 2014!

COS 126 Written Exam 2, Fall 2009

COS 126 Written Exam 2 (Spring 2015)

COS 126 MIDTERM 1, FALL

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

COS 126 General Computer Science Spring Midterm 1

Midterm 1 Written Exam

COS 126 General Computer Science Fall Exam 1

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

COS 126 Midterm 1 Written Exam Fall 2013

Lec 3. Compilers, Debugging, Hello World, and Variables

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

COS 226 Midterm Exam, Spring 2011

COS 126 Midterm 2 Programming Exam Fall 2012

ECE264 Fall 2013 Exam 1, September 24, 2013

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

Question: Total Points: Score:

Introduction to Computer Science Midterm 3 Fall, Points

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

CS 101 Spring 2007 Midterm 2 Name: ID:

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

Some Sample AP Computer Science A Questions - Solutions

Question: Total Points: Score:

COS 226 Midterm Exam, Spring 2009

COS 126 General Computer Science Fall Programming Exam 2

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

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

Basic Operations jgrasp debugger Writing Programs & Checkstyle

COS 226 Algorithms and Data Structures Spring Midterm

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

COS 126 General Computer Science Spring Written Exam 2

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

COS 126 General Computer Science Spring Exam 2

Full file at

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

CS 101 Fall 2005 Midterm 2 Name: ID:

JAVA OPERATORS GENERAL

3. Java - Language Constructs I

Do not start the test until instructed to do so!

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

COS 226 Algorithms and Data Structures Fall Midterm

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Computer Programming, I. Laboratory Manual. Final Exam Solution

CS 101 Exam 2 Spring Id Name

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

Do not start the test until instructed to do so!

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CS 101 Fall 2006 Midterm 3 Name: ID:

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

COS 226 Algorithms and Data Structures Spring Midterm Exam

Name CIS 201 Midterm II: Chapters 1-8

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

ASSIGNMENT 5 TIPS AND TRICKS

CS171 Midterm Exam. October 29, Name:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CDS Computing for Scientists. Midterm Exam Review. Midterm Exam on October 22, 2013

COS 126 Exam Review. Exams overview Example programming exam Example written exam questions (part 1)

Introduction. Lecture 1 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

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

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

Do not start the test until instructed to do so!

COMP-202: Foundations of Programming

CS 177 Spring 2010 Exam I

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Question: Total Points: Score:

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

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

COS 226 Algorithms and Data Structures Fall Final

Lexical Considerations

CEN 414 Java Programming

What does this print?

Chapter 3: Operators, Expressions and Type Conversion

Name: University of Michigan uniqname: (NOT your student ID number!)

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

King Saud University College of Computer and Information Sciences Computer Science Department

Chapter 2 Elementary Programming

COS 126 Written Exam 2 Spring 18

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

Final Examination CS 125 Introduction to Computer Science Fall Hours

Zheng-Liang Lu Java Programming 45 / 79

Java Basics Programming Fundamentals

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Java Simple Data Types

Problem Score Max Score 1 Syntax directed translation & type

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Transcription:

NAME: login ID: precept: COS 126 Midterm 1 Written Exam, Fall 2009 This test has 8 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators or other electronic devices are permitted. Give your answers and show your work in the space provided. Print your name, login ID, and precept number on this page (now), and write out and sign the Honor Code pledge before turning in the test. You have 50 minutes to complete the test. "I pledge my honor that I have not violated the Honor Code during this examination." 1 /6 Signature 2 /5 3 /5 4 /5 5 /5 6 /12 7 /12 8 /10 TOTAL /60 October 22, 2009

1. Number conversion (6 points). Give the representation of the decimal number 1126 in the following number systems. A. Binary (base 2) 100 0110 0110 B. Hexadecimal (base 16) 466 C. Octal (base 8) 2146 2. Short answer (5 points). A. Which Java data type has only two values? boolean B. True or false: Any for loop can be converted to an equivalent while loop. true C. What is the value of the Java expression (.2 * (10/4))? 0.4 D. What is the value of the Java expression ((.2 * 10)/4))? 0.5 E. What is the value of the Java expression (.2 * (10/4.0))? 0.5 3. Standard input (5 points). What are the reasons that a program might take input from standard input rather than from the command line? A. To allow inputs that consist of more than one line. B. To allow inputs that come from a file. C. To allow the program to adapt the inputs it requests, based on prior inputs. D. All of the above. E. None of the above. 2

4. TOY (5 points). An integer array is stored starting at memory location 51. The length of the array is stored in memory location 50. The following (partial) TOY program reverses the array by swapping the first element and the last element, then swapping the second element and the next-to-last element, and so on until the lo and hi pointers cross. Fill in the 5 missing instructions in the blanks provided below. You must select instructions from the following list. 2423 2432 7251 7350 8250 8251 8350 A502 B502 C015 D015 10: 7101 R[1] <- 01 R[1] gets constant 1 11: 7251 R[2] <- 51 addr of first element (lo) 12: 8350 R[3] <- mem[50] 13: 1323 R[3] <- R[2] + R[3] 14: 2331 R[3] <- R[3] - R[1] addr of last element (hi) 15: 2423 R[4] <- R[2] - R[3] 15-16 exit loop if hi < lo 16: D41E if (R[4] > 0) pc <- 1E 17: A502 R[5] <- mem[r[2]] 18: A603 R[6] <- mem[r[3]] 19: B503 mem[r[3]] <- R[5] 1A: B602 mem[r[2]] <- R[6] 1B: 1221 R[2] <- R[2] + R[1] increment lo pointer 1C: 2331 R[3] <- R[3] - R[1] decrement hi pointer 1D: C015 if (R[0] == 0) pc <- 15 1E: 0000 halt 50: 0005 51: 1234 52: 5678 53: 9AA9 54: 8765 55: 4321 The TOY reference card is on the last page of the exam. Feel free to tear out the last page in order to use it more easily. 3

5. Functions (5 points). What does the following program print? Write your answer in the blank space at the bottom of the page, below the code. public class Functions { public static void printvalues(int v) { v = v-1; System.out.println("Out of " + v + " points."); public static void printvalues(double v) { System.out.println("My score will be " + v + " points."); public static void printvalues(int x, double y) { System.out.print("I will get " + x + " of "); System.out.println(y + " points on this question."); public static void printvalues(double x, int y) { System.out.print("Of all the " + x + " points, "); System.out.println("I will receive " + y + " of them."); public static void main(string[] args) { // Initialize the variables int i = 10; double d = 9.5; // Call some printing functions printvalues(d); printvalues(i); printvalues(i, d); My score will be 9.5 points. Out of 9 points. I will get 10 of 9.5 points on this question. 4

6. Recursive method (12 points). Consider the following (recursive) static method. public static char mystery(string s, int n, int m) { if (n == 1) return s.charat(m); char first = mystery(s, n / 2, m * 2); char second = mystery(s, n / 2, m * 2 + 1); System.out.print(first + " " + second + " "); return first; A. Give the return value when this method is called with mystery("abc", 2, 0) a B. Give the return value when this method is called with mystery("abcd", 3, 1) c C. What is printed when this method is called with mystery("fredpass", 5, 1) passps 5

7. Debugging (12 points). Consider the following program, which is supposed to read in integer N from standard input, read N strings from standard input, and print them to standard output in reverse order. 1 public class ReverseInputBuggy 2 { 3 public static void main(string[] args) 4 { 5 int N = StdIn.readInt(); 6 String s; 7 for (int i = 1; i < N; i++) 8 s[i] = StdIn.readString(); 9 for (int i = N; i >= 0; i--) 10 System.out.println(s[i]); 11 12 This program has three bugs. A. Which bug prevents the program from compiling successfully? Identify the line number where the bug appears and give a correct version of this line of code. Line number 6 Correct version: String [] s = new String[N]; B. After fixing the first bug, which bug causes the program to crash? Identify the line number where the bug appears and give a correct version of this line of code. Line number 9 Correct version: for (int i = N - 1; i >= 0; i--) C. After fixing the first two bugs, which bug causes the program to produce incorrect output? Identify the line number where the bug appears and give a correct version of this line of code. Line number 7 Correct version: for (int i = 0; i < N; i++) 6

8. Performance (10 points). The following table gives approximate running times for a program with N inputs, for various values of N. N time 1000 10 seconds 2000 40 seconds 5000 4 minutes 10,000 16 minutes Which of the following best describes the likely running time of this program for N = 100,000? A. A few minutes B. A few hours C. A day D. A month E. A few years Refine a power-law hypothesis to give a formula for the approximate likely running time (in minutes) of this program as a function of N. You need to find the exponent (rounded to an integer) and the leading constant (use scientific notation). a = 1.667e-7 b = 2 7