Question: Total Points: Score:

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

Instructor: Yu Wang 11/16/2012

Question: Total Points: Score:

Question: Total Points: Score:

Question: Total Points: Score:

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

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

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

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

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

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

Question: Total Points: Score:

Question: Total Points: Score:

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

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

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

Question: Total Points: Score:

Question: Total Points: Score:

Question: Total Points: Score:

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

Question: Total Points: Score:

Place your name tag here

Question: Total Points: Score:

CS 190 Exam 2 Fall 2014

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

CS170 (005): Introduction to Computer Science Exam 2

Exam Percentage: / 55 = %

CS 110 Exam 2 Fall 2011

CS 155 Exam 2 Spring 2015

CS 1301 Exam 1 Fall 2010

CS 110 Exam 2 Spring 2011

Question: Total Points: Score:

CS 1301 Exam 1 Fall 2010

CS 2316 Exam 4 Fall 2012

CS 2316 Exam 1 Spring 2014

CS 1301 Exam 1 Fall 2011

CS Exam 2 - Spring 2010

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 3 Spring 2014

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

CS 1301 Exam 3 Fall 2014

CS 110 Exam 1 Fall 2011

CS 190 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Spring 2011

CS 1803 Fall 2010 Exam 1

CS Exam 3 - Spring 2010

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 2 Fall 2013

CS 1301 Exam 2 Fall 2014

CS Name : Grading TA:

CS 2316 Exam 4 Fall 2012

CS 1803 Fall 2010 Exam 1

CS Exam 3 - Spring 2010

CS 2316 Exam 1 Spring 2013

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 1 Fall 2013

CS 1316 Exam 1 Summer 2009

CS 2316 Exam 4 Fall 2011

CS 2316 Exam 3 Fall 2011

CS 1301 Exam 1 Spring 2015

CS 1301 Exam 1 Fall 2013

CS 2316 Exam 4 Fall 2014

CS 1301 Exam 2 Spring 2014

CS 2316 Exam 4 Spring 2013

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

CS 2316 Exam 2 Summer 2011

CS 1301 Exam 2 Fall 2010

CS 1301 Exam 3 Spring 2012

CS 1301 Exam 1 Fall 2009

CS 1301 Exam 3 A Spring 2015

CS 2316 Exam 3 Fall 2012

CS 2316 Exam 4 Spring 2012

CS 2316 Exam 3 Spring 2013

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 1301 Exam 1 Answers Fall 2009

COS 126 Midterm 1 Written Exam Fall 2011

CS 1301 Post Exam 3 Practice Spring 2016

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

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

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

CS 2316 Exam 3 Summer 2014

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

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

CS 101 Spring 2007 Midterm 2 Name: ID:

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

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CS Week 5. Jim Williams, PhD

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

COS 126 General Computer Science Fall Written Exam 1

Following is the general form of a typical decision making structure found in most of the programming languages:

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CS 132 Midterm Exam Fall 2004

CS 1316 Exam 2 Summer 2009

COS 126 Midterm 1 Written Exam, Fall 2009

Transcription:

CS 170 Exam 2 Section 002 Fall 2013 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than the professor/proctor for ANY reason in ANY language in ANY manner. This exam is closed notes, closed books, and no calculator. Turn all mobile devices off and put them away now. You cannot have them on your desk. Write neatly and clearly indicate your answers. What I cannot read, I will assume to be incorrect. Stop writing when told to do so at the end of the exam. I will take 5 points off your exam if I have to tell you multiple times. Academic misconduct will not be tolerated. Suspected academic misconduct will be immediately referred to the Emory Honor Council. Penalties for misconduct will be a zero on this exam, an F grade in the course, and/or other disciplinary action that may be applied by the Emory Honor Council. Time: This exam has 6 questions on 8 pages including the title page. Please check to make sure all pages are included. You will have 50 minutes to complete this exam. I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Emory community. I have also read and understand the requirements and policies outlined above. Signature: Question: 1 2 3 4 5 6 Total Points: 10 20 20 15 20 15 100 Score: 1

1. (10 points) For each entry below, state whether the code is correct as written or has an error. Show where the error is (you can circle the incorrect code) and explain why it is an error. Code Error? Why? int[] A={1,2; Yes Length of array A is 2. int k = A[3]; Index 3 is out of bounds String str = "CD170"; str.charat(1)= S ; Yes charat returns a character, nothing can be assigned to it. public static boolean L(int k){ if (k>0) Yes Method should return 1; return a boolean else return -1; int[][] A = new int[2][2]; Yes Index out of bounds A[2][2]=1; String str1 = "Wahr"; char c0 = str1.charat(0); char c3 = str1.charat(3); String str3 = c3+" "+c0; No String str = "Rana"; Yes str is a string, not int k=str.length; an array, so the appropriate way System.out.print("Length is "+k); is str.length( ) 2

2. (20 points) Consider the program Parameters which is given below. Assume that the program compiles and runs. public class Parameters{ public static int var = 10; public static double x = 5.0; public static boolean Method1(int k, int[] a){ int j=k++; int[] b = a; b[0]=j; a[1]=k; k+=2; Parameters.var--; return (a[1]==b[0]); public static void main(string[] args){ int[] array = {1,3,5,7,9; int k = array[3]; Parameters.var+=2; if(method1(k, array)) System.out.println("Method is true"); else System.out.println("Method is not true"); 1. What type of variable(s) does Method1 return? boolean 2. What type of variable(s) does Method1 take as an input? an integer and an array of integers. 3. What is (are) the class variable(s)? int var and double x 4. What would the program print? 3

Method is not true 5. What is the value of k at the end of the main method? 7 6. Draw the final version of array at the end of the main method. {7, 8, 5, 7, 9 7. Draw the final version of the array b at the end of Method1 {7, 8, 5, 7, 9 8. What is the value of var at the end of the main method? 11 4

3. (20 points) Consider the following methods. 1. What is each one of these algorithms accomplishing? /*---------------Code M1---------------------------*/ public static int M1(int[] A){ for(int i=0; i<a.length-1; i++) if(a[i]>a[i+1]) return (i+1); return -1; /*--------------Code M2----------------------------*/ public static boolean M2(int[] A){ boolean flag = true; for(int i=0; i<a.length-1; i++) if(a[i]>a[i+1]){ flag = false; break; return flag; /*---------------Code M3---------------------------*/ public static boolean M3(int[] A){ for(int i=a.length-1; i>0; i--) if(a[i]<a[i-1]) return false; return true; /*-----------------Code M4-------------------------*/ public static boolean M4(int[] A){ int i=0; while(i<a.length-1){ if(a[i]>a[i+1]) return false; i++; return true; 2. Which methods are doing the same thing? M2, M3, and M4 all return true if the array is sorted, or false otherwise. M1 returns -1 if the array is sorted, or the first position that is not sorted. 5

4. (15 points) Draw the array that would result after the following code is executed: 1. int[] A={1,3,4,8,1; for (int i=a.length-1; i>=0; i--) A[i]=(int)((A[i]-A[0])/2); {0, 1, 1, 3, 0 2. char[] C = { A, E, I, O, U ; char aux = C[0]; for(int i=0; i<c.length-1; i++) C[i]=C[i+1]; C[C.length-1]=aux; { E, I, O, U, A 3. int[] A={1,3,4,8,1,6; for (int i=0; i<a.length; i++) if(a[i]%2==0) A[i]*=2; else A[i]++; {2,6,8,16,2,12 6

5. (20 points) Write the method post7. Given a non-empty array of ints, return a new array containing the elements from the original array that come after the last integer 7 in the original array. The original array will contain at least one 7. Note that it is valid in java to create an array of length 0. post7({2, 7, 1, 2) => {1, 2 post7({7, 1, 7, 2) => {2 post7({7, 7, 1, 2, 3) => {1, 2, 3 public int[] post7(int[] A) { int pos; for(pos=a.length-1; pos>=0; pos--) if(a[pos]==7) break; int[] B = new int[a.length-pos-1]; for(int i=0; i<b.length; i++) B[i]=A[pos+1+i]; return B; 7

6. (15 points) You are given a 2D Java array with 100 rows and 100 columns double[][] M = new double[100][100]; Suppose that M is already full of double values. 1. Write a method called getcol that, given M of any size and an integer k as input, returns a 1D array with the elements of its kth column. You can assume that the number k is always less or equal to the total number of columns. public static double[] getcol (double[][] M, int k){ double[] kcolumn = new double [M.length]; for (int i=0; i<m.length; i++) kcolumn[i]=m[i][k]; return kcolumn; 8