Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

Similar documents
Department of Computer Science Purdue University, West Lafayette

FORM 2 (Please put your name and form # on the scantron!!!!)

Introduction to Computer Science Midterm 3 Fall, Points

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

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

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

Final Exam CS 251, Intermediate Programming December 13, 2017

Exam 1 - (20 points)

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

CS201- Introduction to Programming Current Quizzes

Practice Midterm 1. Problem Points Score TOTAL 50

Introduction to Programming (CS112): Sample

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

Midterm Exam CS 251, Intermediate Programming October 8, 2014

MIDTERM EXAMINATION - CS130 - Spring 2003

COS 126 General Computer Science Spring Written Exam 1

CS 101 Fall 2006 Midterm 3 Name: ID:

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

Key Java Simple Data Types

CS 101 Spring 2007 Midterm 2 Name: ID:

Selected Questions from by Nageshwara Rao

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CS 180 Problem Solving and Object Oriented Programming Fall 2011

CS100M November 30, 2000

CS111: PROGRAMMING LANGUAGE II

CS 177 Week 15 Recitation Slides. Review

Prelim One Solution. CS211 Fall Name. NetID

Final Exam CS 251, Intermediate Programming December 10, 2014

Java Simple Data Types

CS 61B Data Structures and Programming Methodology. June David Sun

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Practice Midterm 1 Answer Key

CSE 113 A. Announcements - Lab

COS 126 Midterm 1 Written Exam, Fall 2009

CSE 131 Introduction to Computer Science Fall Exam II

Midterm Exam CS 251, Intermediate Programming March 6, 2015

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

I. True/False: (2 points each)

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

CS 113 MIDTERM EXAM 2 SPRING 2013

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger and Josh Hug

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

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

Question: Total Points: Score:

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

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

CPSC Fall L01 Final Exam

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

It is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff();

1 Method Signatures and Overloading (3 minutes, 2 points)

I. True/False: (2 points each)

(3) Some memory that holds a value of a given type. (8) The basic unit of addressing in most computers.

CS 101 Spring 2006 Final Exam Name: ID:

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Introduction to Programming Using Java (98-388)

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CS 101 Fall 2005 Midterm 2 Name: ID:

Synchronization Spinlocks - Semaphores

I. True/False: (2 points each)

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

1 Lexical Considerations

Lexical Considerations

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

This exam is open book. Each question is worth 3 points.

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

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

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016

CS1800 Discrete Structures Final Version A

Final Exam Practice. Partial credit will be awarded.

Practice exam for CMSC131-04, Fall 2017

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

Introduction to Java

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CS302: Self Check Quiz 2

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CSE 131 Introduction to Computer Science Fall Final Exam

CSC Java Programming, Fall Java Data Types and Control Constructs

CS 367: Introduction to Data Structures Midterm Sample Questions

CS 101 Fall 2006 Midterm 1 Name: ID:

CS171:Introduction to Computer Science II

1 Looping Constructs (4 minutes, 2 points)

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

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

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

MA FINAL EXAM INSTRUCTIONS VERSION 01 DECEMBER 9, Section # and recitation time

Homework #3 CS2255 Fall 2012

Final Examination CS 125 Introduction to Computer Science Fall Hours

Computational Expression

CSC 1351: Quiz 6: Sort and Search

CMPT-166: Sample Final Exam Answer Key

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

Transcription:

Department of Computer Science Purdue University, West Lafayette Fall 2011: CS 180 Problem Solving and OO Programming Final Examination: Part A. You may consult the textbook and your hand written notes. Friday December 16, 2011 1:00-3:00 pm. LAMBF101. Name: CS Login ID: Recitation Section: Make sure your CS Login ID appears at the top of each page. This exam has two parts. Part A has 10 multiple choice questions. Part B has two programming problems. Complete Part A, return to the proctor and get Part B. Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet. Part A is worth 10 points and Part B worth 20 points. Q 1 Consider the following statement sequence S1. public c l a s s ArrayTest { public s t a t i c void exchange ( int [] a, int [] b){ int [] temp ; temp =a; a=b; b= temp ; public s t a t i c void main ( String [] arg ){ int [] x={1, 2, 3, y={4, 5, 6; exchange (x, y); System. out. println (x [0]+ " "+y [0]); Upon execution of S1 (a) 4 1 is printed (b) 5 2 is printed (c) an array index out of bounds exception is generated (d) 1 4 is printed

Purdue ID: Q 2 Consider the following method. public int GCD ( int x, int y){ i f (x ==0) return y; e l s e { return(gcd (y, x%y )); When called as GCD(6, 4) (a) it will return 1 (b) it will return 2 (c) it will return generate an arithmetic exception (d) it will return 6 Q 3 Consider the following statement sequence S2: int [] a={2, -2, 4; int x=2, index =1; boolean found = f a l s e ; while(index <a. length &&! found ){ i f (x==a[ index ]){ found = true ; break; // End of if index ++; // End of while i f ( found ){ System. out. println ("x is in a"); e l s e { System. out. println ("x is not in a"); // End of if Execution of S2 will (a) display: x is in a (b) display: x is not in a (c) display: 2 (d) result in a run time exception Q 4 Consider the following statement sequence S3: S3 will int [] a ={1; a [0]=5; System. out. println (a [1]); (a) result in a run time exception (b) display: 6 (c) result in a compile time error (d) display: 5 CS 180. Fall 2011. Final Exam. Part A. Page 2 of 4

Purdue ID: Q 5 Consider the following statement sequence S4: public void increment ( int [] x){ x [1]= x [1]+1; public s t a t i c void main ( String [] arg ){ int [] p ={5; increment (p); System. out. println (p [0]); Execution of S4 will (a) result in a run time exception (b) display: 6 (c) display: 5 (d) display: 1 Q 6 Consider the following statement sequence S5: S5 will public s t a t i c void test ( int [] x, int index ){ x[ index ]=x[ index ]+1; public s t a t i c void main ( String [] arg ){ int [] a={2, -2, 4; test (a, 1); System. out. println (a [1]); (a) display: 3 (b) result in a compile time error (c) display: 5 (d) display: -1 Q 7 Consider the following declaration: public c l a s s Mango extends Fruit implements FruitMarket, MyListener { Based on the above declaration which one of the following conclusions is incorrect? (a) FruitMarket is an interface (b) MyListener is an interface (c) Mango is an object (d) Fruit is a class CS 180. Fall 2011. Final Exam. Part A. Page 3 of 4

Purdue ID: Q 8 Class X implements ActionListener and MouseListener. statements is incorrect? Which one of the following (a) X must implement the mouseexited method. (b) X must implement the mousepressed method and the actionperformed method. (c) X must implement the actionperformed method and all methods in the MouseListener interface. (d) X must implement all methods in MouseListener but need not implement the actionperformed method. Q 9 Consider the following methods public s t a t i c int find ( int x, int y){ return (1); public s t a t i c int find ( int [] x, f l o a t [] y){ return (2); public s t a t i c int find ( int x[], f l o a t y){ return (3); public s t a t i c int find ( int x, f l o a t y) {return (4); Now consider the following statement sequence S6: int [] a=new int [10]; int b =0; int z= find (a, b); System. out. println (z); What will be displayed when S6 is executed? (a) 4 (b) 3 (c) 2 (d) 1 Q 10 Variables x and y are declared in class Test as follows: public c l a s s Test { private s t a t i c int x; public int y; public s t a t i c void main ( String args []){ System. out. println (x+" "+y); Which one of the following statements is incorrect regarding the use of x and y in the program above? (a) x can be used in main(). (b) x cannot be used in a class other than Test. (c) y can be used in a class other than Test. (d) y can be used in main(). <End of Part A of Final exam CS 180. Fall 2011.> CS 180. Fall 2011. Final Exam. Part A. Page 4 of 4

Department of Computer Science Purdue University, West Lafayette Fall 2011: CS 180 Problem Solving and OO Programming Final Examination. Part B. You may consult any book and your notes. Friday December 16, 2011 1:00-3:00 pm. LAMBF101. Name: CS Login ID: Recitation Section: Make sure your CS Login ID appears at the top of each page. Ignore import statements. Write ONLY the part of the code you are asked to write. Q 1 In this question you are required to write three methods. Do not write any import statements or class declarations. Simply write the method requested. A correctly written method is worth 3 points. There is no partial credit in this question for a method. All methods are public but not static. (i) Method rotate takes a single dimensional array of characters named mychars as an input parameter. It rotates the contents of mychars to the right by one position. The method does not return any value, it simply changes the array that is input as a parameter. Following are two examples (the dash (-) is used below to indicate a space character). Example 1: mychar= [a b c - -] mychar (after rotation)= [- a b c -] Example 2 mychar= [9 5 * 3 c / p] mychar(after rotation)= [p 9 5 * 3 c /] Write the rotate method on the following page.

// Code for rotate() begins here // Code for rotate ends here. CS 180. Fall 2011. Final Exam. Part B. Page 2 of 8

(ii) Consider the following recursive definition of a sequence t: t 1 = 10 t n = t n 1 3; for n > 1 Thus, t 1 = 10, t 2 = 10 3 = 7, t 3 = 7 3 = 4 and so on. Write a recursive method named nextitem() that takes integer n > 0 as input and returns the n th integer in the sequence. For example, if n = 4 then the method should return 0 (because t 4 = t 3 3 = 4 3 = 1). // Code for nextitem() begins here // Code for nextitem() ends here. CS 180. Fall 2011. Final Exam. Part B. Page 3 of 8

(iii) Write a method named simpletimer(). This method takes an integer d as input. It then prints a 1 on the console. Then, after a delay of d seconds, it prints 2. Then, again after a delay of d seconds it prints 3, and so on. The method does not return any value. It exits after d 10 seconds. Thus, for example, if d = 6 then the method exits after 60 seconds. If you need, you may use Thread.sleep() and/or System.currentTimeMillis() while coding this method. // Code for simpletimer()begins here // Code for simpletimer() ends here. CS 180. Fall 2011. Final Exam. Part B. Page 4 of 8

Q 2 You will be writing two classes: Search and Test. Search extends Thread and is used for searching for a given integer in a two dimensional array. Test uses objects of type Search to search for an integer. Class Test: The main() method in this class performs the following tasks in the given sequence. (a) Calls createarray() that returns a two dimensional array of integers. You are not required to write createarray() or even call it; the code to call this method is already added. No credit (b) Creates two objects named s1 and s2 of type Search. Each object takes array x and three integers num, start, and end as inputs, where num is the number to be searched in x. The number is searched among elements of x in rows starting at start and ending at end. For s1, start=1 and end=n/2 and for s2, start=n/2+1 and end=n. 1 point (c) Starts threads s1 and s2. (d) Waits for s1 and s2 to join. 1 point 1 point (e) Calls getresult() in s1 and s2 to obtain the outcome of search. getresult() returns true if the given number exists in the array and false otherwise. 1 point (f) Uses the results obtained from the two objects s1 and s2 to determine whether or not num is found in x. It then prints true if it exists and false otherwise. 1 point Class Search: This class extends Thread. The constructor saves the parameters supplied by main(). 1 point The run() method searches for the given integer in the given array but only among the elements in rows given by main. For example, if the start row is 1 and the end row is 5 then the search is only among the array elements in rows 1, 2, 3, 4, and 5. A private boolean variable found is set to true if the search is successful otherwise it is set to false. 5 points The getresult() method returns found. You are not required to write this method. No credit CS 180. Fall 2011. Final Exam. Part B. Page 5 of 8

// Code for class Test begins here. public c l a s s Test { f i n a l int n =10; // Your program must work for any n >0. int [][] x=new int [n][n]; // Create a 2- dimensional array of integers. public s t a t i c void main ( String [] args ){ x= createarray (n); // Create x // Write below the remainder of the code. \\ End of main () CS 180. Fall 2011. Final Exam. Part B. Page 6 of 8

// Code for class Search begins here. public c l a s s Search { private int [][] x; // A 2- dimensional array of integers. private int num ; // Holds the number to be searched. private int start, end ; // Staring and ending rows in x; private boolean found ; // Outcome of search. public Search (){ // Write code for the constructor. // End of constructor public void run (){ // Write code for run (); // continue on the next page if needed. CS 180. Fall 2011. Final Exam. Part B. Page 7 of 8

// End of run () <End of Part B of Final exam CS 180. Fall 2011.> CS 180. Fall 2011. Final Exam. Part B. Page 8 of 8