CSE 131 Introduction to Computer Science Fall Exam II

Similar documents
CSE 131 Introduction to Computer Science Fall Exam II

CSE 131 Introduction to Computer Science Fall Exam I

CSE 131 Introduction to Computer Science Fall Final Exam

CSE 131 Introduction to Computer Science Fall Exam II

CSE 131 Introduction to Computer Science Fall Exam I

CSE 131 Introduction to Computer Science Fall Exam I

CSE 131S Introduction to Computer Science Summer SON Exam I

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

CSE 131 Introduction to Computer Science Fall Exam III

CSE 247 Data Structures and Algorithms Fall Exam I

CSE 131S Introduction to Computer Science Summer SON Exam III

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

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

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

Final Exam. COMP Summer I June 26, points

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

COS 126 General Computer Science Spring Written Exam 1

CS 111X - Fall Test 1

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE wi Midterm Exam 2/8/18. Name UW ID #

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

AP Computer Science Unit 1. Writing Programs Using BlueJ

CS100M November 30, 2000

CSE 11 Midterm Fall 2008

CS 3114 Data Structures and Algorithms Test 1 READ THIS NOW!

CS 101 Spring 2007 Midterm 2 Name: ID:

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

2. [20] Suppose we start declaring a Rectangle class as follows:

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

(the bubble footer is automatically inserted into this space)

About this exam review

Final Exam COMP Fall 2004 Dec 16, 2004

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

Neatly print first and last names: Exam II. "On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work.

16.216: ECE Application Programming Fall 2011

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.

CSE 11 Style Guidelines

COMP 401 Spring 2014 Midterm 1

COS 126 Midterm 1 Written Exam Fall 2012

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

COS 126 Exam 2 Review Part 1

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

PREPARING FOR PRELIM 2

Math 52 - Fall Final Exam PART 1

ENGR 100 Midterm (CSE Part) Winter 2014

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

Note that there are questions printed on both sides of each page!

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CMSC 331 Second Midterm Exam

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

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

Department of Networks College of Bardarash Technical Institute DUHOK Polytechnic University Subject: Programming Fundamental by JAVA Course Book

CS 1301 Exam 1 Fall 2010

AP Computer Science Unit 1. Writing Programs Using BlueJ

CMPSCI 187: Programming With Data Structures. Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)

I. True/False: (2 points each)

Final Exam Winter 2013

CS 1301 Exam 1 Fall 2010

Exam Percentage: / 55 = %

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

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

CS 1110 Final, December 16th, 2013

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

a f b e c d Figure 1 Figure 2 Figure 3

CS Prelim 2 Review Fall 2018

CSE wi Final Exam 3/12/18. Name UW ID#

INSTRUCTIONS TO CANDIDATES

CS-202 Introduction to Object Oriented Programming

COS 126 General Computer Science Fall Written Exam 1

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

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

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

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

Final Examination CS 125 Introduction to Computer Science Fall Hours

CS Exam 2 - Spring 2010

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

CS164: Midterm I. Fall 2003

CMPSCI 187 / Spring 2015 Hangman

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

CS 2505 Computer Organization I

Mathematics Concepts 2 Exam 1 Version 2 22 September 2017

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Midterm Exam 2 CS 455, Spring 2015

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

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

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

CS 1110 Final, December 8th, Question Points Score Total: 100

UNIVERSITY REGULATIONS

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

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

CISC 1600 Lecture 3.1 Introduction to Processing

Welcome to CompSci 201

COS 126 Midterm 1 Written Exam Fall 2011

Discrete Mathematics and Probability Theory Fall 2015 Rao Midterm 1

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Announcements. 1. Forms to return today after class:

Transcription:

CSE 131 Introduction to Computer Science Fall 2015 Given: 5 November 2015 Exam II Due: End of Exam Session This exam is closed-book, closed-notes, no electronic devices allowed. The exception is the sage page on which you may have notes to consult during the exam. Answer questions on the pages of the exam. Do not unstaple the pages of this exam, nor should you attach any other pages to the exam. You are welcome to use the blank space of the exam for any scratch work. Your workmustbelegible. Work that isdifficulttoread willreceive nocredit. Donot dwell over punctuation or exact syntax in code; however, be sure to indent your code to show its structure. You must sign the pledge below for your exam to count. Any cheating will cause the students involved to receive an F for this course. Other action may be taken. If you need to leave the room for any reason prior to turning in your exam, you must give your exam and any electronic devices with a proctor. You must fill in your identifying information correctly. Failure to do so is grounds for a zero on this exam. When you reach this point in the instructions, please give the instructor or one of the proctors a meaningful glance. Print clearly the following information: Name (print clearly): Student 6-digit ID (print really clearly): Your answers below tell us where to return your graded exam. What time do you actually attend studio/lab? What room (222, 218, 216, or 214)? your best guess Problem Possible Received Number Points Points 1 20 2 10 3 15 4 15 5 20 6 20 Total 100 Pledge: On my honor, I have neither given nor received any unauthorized aid on this exam. Signed: (Be sure you filled in your information in the box above!)

CSE 131 (Exam II) 2 Due by End of Exam Session 1. (20 points) The bulleted items below have blanks where some information is missing. For each blank, fill in the letter 1 that fits best conceptually where the blank occurs. You may have to use a given letter more than once; some letters may not belong in any of the blanks. When describing the nature of an object via a story, each of the story usually corresponds to an instance variable for the resulting class. We avoid writing similar code multiple times by capturing the basic idea of the codeina. Ifthatcoderequiressomevariationinitsexecution, then are provided so that different values can be supplied at different times for its execution. Themethodthatisresponsible forgivingbirthtoaclassiscalleda. That method is also responsible for initializing the class s. If a class C s instance variables are declared final, this has the effect of making all instances of C. Wecansometimes formulateamethodbyhaving itcalla smaller instanceofthe problem it sets out to solve. This technique is know as. Without a, such methods would in theory never terminate. IfaclassChasinstancevariablesthatareprivate, thencmustinclude for those instance variables if their values are needed outside of C. A for a class is that class s only method that hasno declared return type (i.e., int, void, etc.). a Method b Instance variables c Parameters d Recursion e Base case f Immutable g Setters h boolean i tostring() j Constructor k Has-a l Getters 1 Do not write the term or phrase in the blank space! Use a letter from the provided list.

CSE 131 (Exam II) 3 Due by End of Exam Session 2. (10 points) Consider the following unusual definition of isodd(int n): isodd(n 2),if n 2 isodd(n) = (a) (5 points) The above definition is missing something. What is it missing? (b) (5 points) The code corresponding to the definition above is given below. Without changing the code given, and without making any other recursive calls, complete the code so that it works properly for any n 0. 2 public static boolean isodd(int n) { if (n >= 2) { return isodd(n-2); 2 For n < 0, you can do whatever you like. We won t grade on that behavior.

CSE 131 (Exam II) 4 Due by End of Exam Session 3. (15 points) Consider the following recursive formula: { 3 f(n 1)+4,if n > 0 f(n) = 1, otherwise (a) (5 points) Below, write the code for f: public static int f(int n) { (b) (10 points) Below, using substitution, show the evaluation of f(2), making sure you transcribe lines faithfully down the page, so that each line you write is truly equal to f(2): 3 f(2) = = = = = = 3 You may or may not need all of the lines provided; also, use more if you need them.

CSE 131 (Exam II) 5 Due by End of Exam Session 4. (15 points) Consider the method: public static int foo(int x, int y, int z) { return x + y + z; and a call to that method: a = foo(b, c, d); (a) (10 points) In the call to foo, just prior to foo s execution, if the stack is as follows: 3 2 1 then what must have been the values of b? c? d? (b) (5 points) Below, show the stack just prior to foo returning the answer that will be assigned to a:

CSE 131 (Exam II) 6 Due by End of Exam Session 5. (20 points) Recall the API for drawing as square is as follows: StdDraw.square(x,y,r) draws a square centered at coordinate (x,y) whose half width and half height are both r. For example, given the default coordinates of a Sedgewick canvas, the call StdDraw.square(0.5, 0,5, 0.5) draws a single square centered on the screen at (0.5,0.5). Its lower left corner is at (0,0) and its upper right corner is at (1,1). It is in fact the outermost square in the following image: In the above image, each contained square s half-width is 0.03 Sedgewick units less than its containing square. In this problem you develop a recursive solution to drawing the image shown above. (a) (5 points) Describe the substructure of the image you see above. More specifically, if the entire image contains squares whose half-widths are no more than 0.5, then how would you describe the next smaller instance of that image? (b) (5 points) Describe the base case of the recursion present in the above image. Continued on next page...

CSE 131 (Exam II) 7 Due by End of Exam Session (c) (10 points) Complete the squares method below so that it draws (something resembling) the image above. Be sure to circle the base case in your code. /** * * @param x x-coordinate of the center of this square * @param y y-coordinate of the center of this square * @param hw the half-width (and thus half-height) of this square */ public static void squares(double x, double y, double hw) { Complete this method (5 points) I left you more room below than you probably need Circle the base case! (5 points) public static void main(string[] args) { Start recursion using the unit square, centered at (0.5,0.5) and with a half-width of 0.5 Do not change this method! squares(0.5, 0.5, 0.5);

CSE 131 (Exam II) 8 Due by End of Exam Session 6. (20 points) Consider the following user story: A (3-dimensional) Box has-a width length height indication of whether the Box is currently open or closed In terms of behavior, our Box object should offer the following functionality: There should be getters, but no setters, for the Box s width, length, and height. There should be a getter and setter for the Box s openness (whether the box is currently open or closed). It should be possible to find the volume of the Box, computed as its width length height. It should be possible to find the area of the bottom of the Box, computed as its width length. It should be possible to determine whether another Box b fits inside this Box, determined as follows: The area of b s bottom must be less than this Box s bottom, and The volume of b must be less than this Box s volume. Note that the above requirements do not print out anything. Your methods therefore should not print anything. Instead they should affect the object by changing its instance variable(s) or by returning appropriately typed values to provide the desired functionality. (a) (3 points) Although you will not generate hashcode or equals, on which of the above has-a s would you base those methods, and why? (b) (17 points) Below, and on the facing page, write the code for your Box class, placing elements of your class between the comments as indicated. public class Box { (4 points) Instance variable(s) below here. For each instance variable, chose a type that best fits its purpose and usage.

CSE 131 (Exam II) 9 Due by End of Exam Session (3 points) Constructor below here. (2 points) tostring() below here. (something very simple: no need to include all instance variables) (8 points) Other methods below here. DO NOT provide equals or hashcode.

CSE 131 (Exam II) 10 Due by End of Exam Session