COS 126 Midterm 1 Written Exam Fall 2011

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

COS 126 Midterm 1 Written Exam Fall 2012

COS 126 Midterm 1 Written Exam Fall 2014!

COS 126 Midterm 1 Written Exam Fall 2013

COS 126 Midterm 1 Written Exam, Fall 2009

COS 126 General Computer Science Fall Written Exam 1

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

COS 126 Midterm 1 Written Exam Spring 2015

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1

COS 226 Midterm Exam, Spring 2011

Midterm 1 Written Exam

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

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

COS 126 General Computer Science Fall Exam 1

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

COS 126 Midterm 2 Programming Exam Fall 2012

COS 226 Midterm Exam, Spring 2009

CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

COS 126 General Computer Science Fall Midterm 1

COS 226 Algorithms and Data Structures Spring Midterm

COS 126 General Computer Science Fall Exam 1

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

COS 126 MIDTERM 1, FALL

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

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

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

CS 101 Spring 2007 Midterm 2 Name: ID:

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

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

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

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

Question: Total Points: Score:

Question: Total Points: Score:

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

COS 126 Written Exam 2, Fall 2009

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

CS170 Introduction to Computer Science Midterm 2

COS 126 General Computer Science Spring Midterm 1

COS 126 Exam 2 Review Part 1

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

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Examination Questions Midterm 1

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Practice Midterm 1. Problem Points Score TOTAL 50

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

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Functions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)

COS 226 Midterm Exam, Spring 2010

COS 126 General Computer Science Fall Exam 1

A Foundation for Programming

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

Repetition with for loops

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

COS 126 Written Exam 2 (Spring 2015)

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

COS 126 General Computer Science Fall Programming Exam 2

Problem Score Max Score 1 Syntax directed translation & type

Lecture 5: Methods CS2301

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

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

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

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points.

COS 226 Algorithms and Data Structures Fall Midterm

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

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

All classes in a package can be imported by using only one import statement. If the postcondition of a method is not met, blame its implementer

CSE 131 Introduction to Computer Science Fall Exam II

CS 111X - Fall Test 1

CSE 1223: Exam II Autumn 2016

Final Exam. COMP Summer I June 26, points

Practice Midterm 1 Answer Key

Question: Total Points: Score:

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

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

CSC 210, Exam Two Section February 1999

CS 101 Fall 2006 Midterm 3 Name: ID:

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

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

CSci 1113 Midterm 1. Name: Student ID:

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

Java Bytecode (binary file)

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

CIS Introduction to Computer Programming Spring Exam 1

CS1150 Principles of Computer Science Loops (Part II)

About this exam review

Learning Goals LG1: Implement the peer instruction process by A) clicking in on an answer B) discussing with your team C) coming to consensus and

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

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

Object- Oriented Analysis, Design and Programming

COS 126 General Computer Science Spring Written Exam 2

Introduction to Software Development (ISD) Week 3

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

Computer Programming, I. Laboratory Manual. Final Exam Solution

Transcription:

NAME: login id: Precept: COS 126 Midterm 1 Written Exam Fall 2011 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 this paper. Note: It is a violation of the Honor Code to discuss this midterm exam question with anyone until after everyone in the class has taken the exam. You have 50 minutes to complete the test. I pledge my honor that I have not violated the Honor Code during this examination. Signature 1 /7 2 /9 3 /7 4 /6 5 /9 6 /8 7 /6 8 /8 TOTAL /60

1. Types and Casts (7 points). Give the type and value of each of the following Java expressions. If an expression will not compile, write Illegal under type and put an X in value. You must fill in every entry. Entries left blank will be marked incorrect. expression type value ( 7 / 2 ) * 2.0 ( 7 / 2.0 ) * 2!(!!false &&!!true) "1.1" + "2.2" (1 < 2 < 3) 1 + 2.2 + "1.1" + "a" Integer.parseInt("123")

2. Array Declarations (9 points). Among the following code fragments, circle the ones that will not cause a compile-time error. A. int[] a = int[10]; B. int[] a = new int[10]; C. int[10] a = new int[10]; D. int[] a = 1, 2, 3; int b = a; E. int[] a; F. int a = 1, 2, 3; G. int[][] a = 1, 2, 3, 1, 2, 3; H. int[][] a = new int[10]; I. int[] a = 1, 2, 3; int[] b = a;

3. Syntax and Scope (7 points). Consider the following code. public class Cubes public static int square(int i) return i * i * i; public static void main(string[] args) for (int i = 1; i <= 1000; i++) StdOut.println(square(i)); Among the following statements, circle those that are true. A. Will not compile because braces in square() are not on separate lines. B. Will not compile because braces are missing in the for loop. C. Will not compile because i is not declared in square(). D. Prints only a few lines because square() rapidly increases the i used by main. E. Prints the squares of the integers from 1 to 1000. F. Prints the cubes of the integers from 1 to 1000. G. Goes into an infinite loop.

4. Piping (6 points). Consider the following Java program: public class EZ public static void main(string[] args) int x = StdIn.readInt(); int y = StdIn.readInt(); StdOut.println(y); StdOut.println(x % y); StdOut.println(x); Assume that the contents of the file input.txt are as shown by the following more command: % more input.txt 83 14 A. What is the result of the following command? Circle your answer. % java EZ < input.txt B. What is the result of the following command? Circle your answer. % java EZ < input.txt java EZ C. What is the result of the following command? Circle your answer. % java EZ < input.txt java EZ java EZ

5. Debugging (9 points). Consider the following code snippet, which is intended to examine an array of double values and print out the minimum value in the array and its location. The line numbers at left are for your convenience in referring to the code. You may assume arr[] is an array of double values that has been properly declared and initialized. 1 int N = arr.length; 2 double min = 0; 3 int minlocation=0; 4 for(int i = 1; i <= N; i++) 5 6 if( arr[i] < min ) 7 min = arr[i]; 8 minlocation = i; 9 10 System.out.print("The minimal value is arr["); 11 System.out.println(minLocation + "] = " + min); In the spaces provided below, identify (in ten words or less, each) three bugs in the code that will result in either an incorrect answer being printed or a program crash. Circle your answers. A. A bug: B. Another bug: C. A third bug:

6. Methods (8 points). For the purpose of this question, assume that you are developing static methods for your own statistics library MyStats. A. (4 points) Write a public static method threeequal() for MyStats that takes three int values as arguments and returns true if all three numbers are equal, false otherwise. B. (2 points) Give the signature of a public static method median() for MyStats that is to take as an argument an array of int values and return the middle value. Do not give the code, just the signature (a single line of code). C. (2 points) Give a single Java expression that a client of MyStats could use to test whether the medians of three arrays of int values int[] a, int[] b, and int[] c are all equal.

7. Performance (6 points). A Python programmer experiences the following approximate running times for a program that reads N numbers, for various values of N. N time 1000 just over 1 second 10000 just under 2 minutes 100000 about 3 hours 1 million? A. Which of the following best describes the likely running time of this program if our programmer were to run it for N = 1 million? Circle your answer. a. About a day b. About two weeks c. About three months d. About four years B. Which of the following best describes the order of growth of the running time of this program? Circle your answer. a. Logarithmic b. Linear c. Linearithmic d. Quadratic e. Cubic

8. Recursive Graphics (8 points). Consider the following recursive method: public static void squarelife(double x, double y, double r) if (r < 0.05) return; //Select a random integer from the set [0, 1, 2, 3, 4] int randomint = (int) (Math.random() * 5); if (randomint < 1) squarelife(x-r, y-r, r/2); if (randomint < 2) squarelife(x-r, y+r, r/2); if (randomint < 3) squarelife(x+r, y-r, r/2); if (randomint < 4) squarelife(x+r, y+r, r/2); //bottom left //top left //bottom right //top right drawshadedsquare(x, y, r); Assume that the helper method method drawshadedsquare() draws a gray shaded square of radius r that is outlined in black and centered on (x, y). A. Suppose that a client program issues the call squarelife(0.5, 0.5, 0.25). Which of the following figures could possibly result? Answer by circling 1, 2, or 3 of the figures. B. Suppose that a client program issues the call squarelife(0.5, 0.5, 0.6). What is the maximum possible number of times drawshadedsquare() could be called as a result? Write your answer in the blank provided. Maximum number of squares drawn: