Final Exam COMP Fall 2004 Dec 16, 2004

Similar documents
Final Exam. COMP Summer I June 26, points

Final Exam Practice. Partial credit will be awarded.

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

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

CS111: PROGRAMMING LANGUAGE II

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

Name CIS 201 Midterm II: Chapters 1-8

Lecture 5: Methods CS2301

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

CS 101 Spring 2007 Midterm 2 Name: ID:

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CS 101 Exam 2 Spring Id Name

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

CS 113 MIDTERM EXAM 2 SPRING 2013

CSE 131 Introduction to Computer Science Fall Exam II

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

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

Selected Questions from by Nageshwara Rao

CSCE 206: Structured Programming in C++

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

I. True/False: (2 points each)

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

Exam Duration: 2hrs and 30min Software Design

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

I. True/False: (2 points each)

Spring 2017 CS 1110/1111 Exam 1

I. True/False: (2 points each)

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

CSE 131S Introduction to Computer Science Summer SON Exam I

CS 177 Week 15 Recitation Slides. Review

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

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

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

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

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

b. Suppose you enter input from the console, when you run the program. What is the output?

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

Fall 2002 Page 1 of 9 READ THIS NOW!

CS 111X - Fall Test 1

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

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Computer Science II (20082) Week 1: Review and Inheritance

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

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

APCS Semester #1 Final Exam Practice Problems

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

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

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

Prelim 1, Solution. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

PROGRAMMING FUNDAMENTALS

CSE 131 Introduction to Computer Science Fall Exam I

CS162 Computer Science I Fall 2018 Practice Exam 1 DRAFT (9 Oct.)

CS170 Introduction to Computer Science Midterm 2

Introduction to Computer Science Midterm 3 Fall, Points

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

COS 126 General Computer Science Spring Written Exam 1

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

CSE 131 Introduction to Computer Science Fall Exam II

Do not start the test until instructed to do so!

Use the scantron sheet to enter the answer to questions (pages 1-6)

CSE 131 Introduction to Computer Science Fall Exam I

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

(the bubble footer is automatically inserted into this space)

Practice Midterm 1. Problem Points Score TOTAL 50

CSE 5A Final Fall 2006

Computer Programming, I. Laboratory Manual. Final Exam Solution

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

CSE 131 Introduction to Computer Science Fall Exam I

Programming: Java. Chapter Objectives. Chapter Objectives (continued) Program Design Including Data Structures. Chapter 7: User-Defined Methods

CSE 143 SAMPLE MIDTERM

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

( &% class MyClass { }

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

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

COMPUTER APPLICATIONS

CSE 11 Midterm Fall 2008

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

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Last Name: Circle One: OCW Non-OCW

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

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

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Practice Midterm 1 Answer Key

Chapter 7 User-Defined Methods. Chapter Objectives

COS 126 General Computer Science Fall Written Exam 1

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

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

Handout 4 Conditionals. Boolean Expressions.

Midterm Practice Problems - answer key Answers appear in boldface.

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

CS 101 Fall 2006 Midterm 3 Name: ID:

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

CSCI 111 Midterm Spring 2014

CS313D: ADVANCED PROGRAMMING LANGUAGE

Transcription:

1. Closed book and closed notes. Final Exam COMP 14-062 Fall 2004 Dec 16, 2004 2. Write all scratch work and answers on the exam itself. If you need extra space, let me know. Indicate your final answer by drawing a box or circle around it. 3. Write legibly. If I can t read it, you can t get credit for it. 4. Write your name on every page of this exam. 5. You do not need to put comments in any code you write. You will not be graded for coding style. 6. Assume any code segment is embedded in a correct program. That is, assume all variables have already been appropriately declared before they are used. I pledge that I have neither received nor given unauthorized aid on this examination. Signed: Printed Name:

1) - Multiple Choice / Fill in the Blank [4 points each, 20 points total] Circle the option that correctly fills the blank 1. A(n) parameter defines what type must be passed to a method. a) actual b) formal c) static d) class 2. An easy way to share a variable between many instances of the same class is to declare the variable as. a) public b) private c) static d) instance data 3. A(n) is a large, integrated collection of data. a) network b) graphics system c) database d) application 4. The presence of the keyword indicates that it is okay to use a method or variable outside of the class in which it is defined. a) static b) final c) public d) private 5. Which of the following behaves most like an array when passed as a parameter? a) int b) String c) char d) static variable

2) Explain Concepts (17pts) a) [8 points] Briefly explain the terms class and object, and describe how they re related to each other. You can use specific examples if you want. b)[9 points (3 each)] Briefly describe the role of each of the following within a class: a) Instance variables b) Instance methods c) Constructors 3) [16 points (4 each)] Write a method header (the very first line of a method) for methods that do each of the following things. Assume that all of these methods are not instance methods (that is, their headers start with the keywords public and static). Do not write the body of the method, just the header. a. A method named printx() that just displays the String X to the output window.

b. A method named doublevalue() that takes in an argument of type int and returns twice the argument s value. c. A method named picount() that takes in an array of doubles and returns the number of elements that are greater than Pi. d. A method named largerthan() that takes in one int and one double and returns true if the int is larger than the double, and false otherwise. 4) Detect Errors: True or False (15pts) If the code segment will compile and run with no errors, write true, otherwise write false. If the code segment will not compile, indicate why. (Each code segment is separate from the others) True or False Example: int number = true; ß different types false

1.) double count = 0; for( int i=0; i<10; i++ ) count += i / (i/2-1); System.out.println( count ); 2.) char c = 'A'; int i = 10; String str = "mystring"; str += c + i; 3.) int sum = 0; for( int i=0; i<100; i+=2 ) sum += i; System.out.println( i ); 4.) int num = 10; boolean valid = ( num < 5 ) && (num/2 == 2); 5.) char ch = 'i'; if( ch >= 'a' && ch <= 'z' ) System.out.println( ch );

5) [12 points] Evaluate the following expressions, given these variable initializations. String str1 = "42, dude." String str2 = "Bananas are for monkeys" int num = 31; a. int val1 = (int)((float)(num / 31 / 1 * 2 / 9) + (int)1.0); b. String val2 = str2.substring(0, 1) + str2.substring(8, 12) + str2.substring(str2.indexof("monkeys")); c. boolean val3 = 30 / num < 7 == str1.length() >= 9; d. String val4 = str2.substring(str2.indexof("n"), 6);

6) [12 points] Show the output produced by the following code. public class MyClass public static void changex() int x = 20; System.out.println(x); public static void incrementx(int x) x++; System.out.println(x); public static int returnx(int x) x = 0; System.out.println(x); return x; public static void main(string[] args) int x = 10; changex(); System.out.println(x); incrementx(x); System.out.println(x); x = returnx(x); System.out.println(x); 7) [15 points] Suppose I ve written a class named Adder. This class has three instance variables, all of type int, whose identifier names are num1, num2, and result. This class has a default constructor that initializes all of the class s instance variables to 0. This class has two instance methods: 1) go() takes two arguments of type int, adds the two arguments, and

stores their sum in the instance variable result; 2) display() prints the current value of result to the output window. Show the output produced by the following code. (Note: You can draw diagrams for partial credit, but the only thing that s required is the output itself.) Adder add1 = new Adder(); Adder add2 = new Adder(); Adder add3 = add1; add1.go(1, 2); add3.display(); add2.num1 = 2; add2.num2 = 4; add1.go(add2.num1, add2.num2); add1.display(); add3 = add2; add2.go(add2.num1*2, add1.result); add3.display(); add1.go(0, ++add1.result); add1.display(); 8) [12 points] Write some code that will declare, initialize, and fill in an array of type int. After your code executes, the array should look as follows. 0 2 4 6 8 10 12 14 16 18

9) [15 points] Show the output produced by the following code. Note: The second and third lines simply initialize arrays of length 5 containing the given values. Ask me if you don t understand those two lines. int i1 = 0, i2 = 0; int[] array1 = 1, 2, 5, 5, 8; int[] array2 = 2, 3, 4, 7, 10; int[] array3 = new int[10]; for (int i3 = 0; i3 < 10; i3++) if (i1 > 4) array3[i3] = array2[i2++]; else if (i2 > 4) array3[i3] = array1[i1++]; else if (array1[i1] < array2[i2]) array3[i3] = array1[i1++]; else array3[i3] = array2[i2++]; for (int i = 0; i < 10; i++) System.out.print(array3[i] + " ");

10) Show the output of the following code segment (20pts) import java.io.*; class testcard public static void main(string[] args) Card card1 = new Card(1, 1); int x = 2, y = 2; System.out.println("outside I: " + card1 + " x is " + x + " y is: " + y); update(card1, x, y); System.out.println("outside II: " + card1 + " x is " + x + " y is: " + y); public static void update(card card1, int x, int y) System.out.println("inside I: " + card1 + " x is " + x + " y is: " + y); x = 3; y = 3; card1.setface(x); card1.setsuit(y); System.out.println("inside II: " + card1 + " x is " + x + " y is: " + y); Given the card class: public class Card private int face; private int suit; public Card(int face, int suit) // initialize the card this.face = face; this.suit = suit; public String tostring () // return a String that contains a text representation of the card String cardname = "face: "; cardname += face + " suit: " + suit; return cardname; public void setface(int f) face = f;

public void setsuit(int s) suit = s;

11) [10 points (5 each)] a. Given the following array, how many times will values be swapped if the array is sorted using selection sort? 2 1 10 5 4 15 b) How many times will a value be inserted into a new position if the same array is sorted using insertion sort? 12) [14 points] predict outputs public class SoyBean private static int numbeans = 0; private int myid; SoyBean() myid = numbeans; numbeans++; public int id() return myid; public class Program public static void main(string[] args) SoyBean b0 = new SoyBean(); SoyBean b1 = b0; SoyBean b2 = new SoyBean(); System.out.println("beans: " + b0.id() + "," + b1.id() +","+ b2.id());

13) [22 points] Provide a definition for the method searchsorted, which takes as input (i.e., parameters) an array of integers sorted in ascending order and an integer target. The method returns true if there is at least one element of the array equal to the target. The method returns false otherwise. Use the fact that the array is sorted to possibly exit the search early. The searchsorted method should be both accessible outside of a class definition and available for invocation without using an object. a) write down the header of the method (7pt) b) write down your design from high level (8pt)

c) write down your code for the method (7pt)