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

Similar documents
COS 126 Exam 2 Review Part 1

COS 126 Midterm 1 Written Exam Fall 2012

COS 126 Midterm 1 Written Exam Fall 2011

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

COS 126 General Computer Science Fall Written Exam 1

COS 126 Midterm 1 Written Exam Fall 2014!

COS 126 General Computer Science Spring Written Exam 1

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

COS 126 General Computer Science Spring Written Exam 1

COS 126 Midterm 1 Written Exam Fall 2013

H212 Introduction to Software Systems Honors

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

Lecture Set 4: More About Methods and More About Operators

ESC101 : Fundamental of Computing

Australian researchers develop typeface they say can boost memory, that could help students cramming for exams.

Midterm 1 Written Exam

COS 126 Midterm 1 Written Exam, Fall 2009

Lecture Set 4: More About Methods and More About Operators

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

Week 6 CS 302. Jim Williams, PhD

CONDITIONAL EXECUTION

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)

A Foundation for Programming

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

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Topic 4 Expressions and variables

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

COMPUTER SCIENCE. 4. Arrays. Section 1.4.

COS 126 General Computer Science Fall Exam 1

CS4961 Parallel Programming. Lecture 12: Advanced Synchronization (Pthreads) 10/4/11. Administrative. Mary Hall October 4, 2011

CS 106 Introduction to Computer Science I

Announcements. 1. Forms to return today after class:

CSE373 Fall 2013, Midterm Examination October 18, 2013

! 52 playing cards in a deck. ! 5 thousand undergrads at Princeton. ! 1 million characters in a book. ! 10 million audio samples in an MP3 file.

Practice Midterm Exam #1

Claremont McKenna College Computer Science

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

COS 126 General Computer Science Fall Exam 1

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

COE318 Lecture Notes Week 4 (Sept 26, 2011)

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

COS 126 General Computer Science Fall Exam 1

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

2.2 Libraries and Clients

Selected Questions from by Nageshwara Rao

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

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

CS 113 MIDTERM EXAM 2 SPRING 2013

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

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

1.4 Arrays. A Foundation for Programming. Many Variables of the Same Type. Arrays. !!! any program you might want to write

CS Programming I: Arrays

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

CS111: PROGRAMMING LANGUAGE II

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Arrays. 1 Index mapping

CS61B Lecture #2. Public Service Announcements:

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Welcome to CompSci 201

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

CONDITIONAL EXECUTION: PART 2

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CS1150 Principles of Computer Science Loops (Part II)

CONDITIONAL EXECUTION

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

Topic 6: Inner Classes

(a) Write the signature (visibility, name, parameters, types) of the method(s) required

CS 1110: Introduction to Computing Using Python Loop Invariants

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

1.4 Arrays. A Foundation for Programming. Arrays. Many Variables of the Same Type. This lecture. Store and manipulate huge quantities of data.

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

University of Palestine. Mid Exam Total Grade: 100

Warm up question. 2)Which of the following operators are defined on a half integer? Which of the following would it be useful to write as behaviors?

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

Programming Problems 22nd Annual Computer Science Programming Contest

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

CS 112 Introduction to Programming

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

CS170 Introduction to Computer Science Midterm 2

TTh 9.25 AM AM Strain 322

CS111: PROGRAMMING LANGUAGE II

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

CS 163 Practice Final Exam Winter 2012

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

Types, Expressions, and States

Sorting. Bubble Sort. Selection Sort

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

Check out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project

Welcome to CS 135 (Winter 2018)

Building Java Programs

Exam I Review Questions Fall 2010

OHJ-306x: Software Testing Introduction to the Course Project Part 1: General Information and Project phases 1 & 2: Unit testing

Transcription:

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

Exams overview (revisited) We have exams in the fall Two written exams. Two programming exams. Prep sessions in class meetings No exam "midterm week" No final exam Programming exams. October 11 and December 6. Mini in-class assignments. Can you write a short program? You will need to practice. Written exams. October 18 and December 13. Written by RS. Note: RS has been known to re-use questions Did you watch the lectures and do the reading? One question per lecture (roughly). 2

Exams tab on the booksite See Exams tab for full details and old exams. Read carefully before each exam. Policies are the contract between us and you. Watch this space for details Policies (programming exam). Open course materials. No other web access. No outside communication. Policies (written exam). Closed book/notes/computer. 1 page (two sides) cheatsheet. 3

Things to remember about inclass exams We know that you don't have much time. Exams are 50 minutes. "One page" programming exams. Five-minute questions on written exams. Exams are only part of the story. We have to grade the exams. 400+ exams. No open-ended questions. Fully prepared rubrics. Old exams are not completely reliable. Course offerings differ slightly. We have made mistakes in the past. 4

Programming Exam Logistics Writing a short program in 50 minutes can be a challenge for anyone. You will use your own computer. You will download and edit a template. You will submit your solution in the same way as you do for assignments. You don't all fit in this room. Pay attention and know where to go. Arrive early. Make sure your computer is charged. Advice: Practice, practice, practice. Write some short programs on your own. Attend the practice programming exam. Try a past programming exam (untimed). Try another one (timed). 5

Programming Exam 1 Part 1 Q. Can you write a simple program on your own? Exams Info gave instructions to load this before the exam Example (Fall 2015). Part 1. Write programs that find the number of distinct values among the integers on standard input, assuming that the input is nonempty and in sorted order. Your task. Add code to the file Count1.java to print the number of integers on standard input and the number of distinct values among those integers. public class Count1 public static void main(string[] args) int count = 1; int distinct = 1; // YOUR CODE HERE you also get a test file and desired output Details. Write a single loop that uses StdIn.readInt() to read each integer one at a time, but do not save them in an array. To compute the number of distinct values, add code to the loop to update distinct if the new value just read differs from the value read just before it. % more testcount1tiny.txt 1 1 1 1 2 2 2 2 4 4 4 4 5 5 6 6 9 9 % java Count1 < testcount1tiny.txt 6 distinct values among 18 integers 6

Programming Exam Strategy Write and submit the easiest code before tackling the hard part. Your task. Add code to print the number of integers on standard input and the number of distinct values among those integers. % more testcount1tiny.txt 1 1 1 1 2 2 2 2 4 4 4 4 5 5 6 6 9 9 % java Count1 < testcount1tiny.txt 1 distinct values among 18 integers % java Count1 < testcount1tiny.txt 6 distinct values among 18 integers public class Count1 public static void main(string[] args) int count = 1; // number of integers int distinct = 1; // number of different ones int val = StdIn.readInt(); while (!StdIn.isEmpty()) int newval = StdIn.readInt(); count++; // count the integers if (newval!= val) distinct++; // count the different ones val = newval; StdOut.println(distinct + " distinct values among " + count + " integers"); 7

Programming Exam 1 Part 2 Q. Can you quickly apply something you have recently learned? Exams Info gave instructions to load this before the exam Example (Fall 2015). Part 2. Assume that the integers on standard input are nonnegative and less than a value M given as the first command-line argument, but not necessarily in order. Details. To compute the needed values, use two loops. First, write a loop that reads the integers one at a time from standard input, counts them, and uses the boolean array b[] to record which values have been seen: when you read a value val, set b[val] to true. Second, write public class Count2 public static void main(string[] args) int M = Integer.parseInt(args[0]); boolean[] b = new boolean[m]; // YOUR CODE HERE the description includes an example a loop that counts the number of true values in b[] (the number of distinct values in the input). 4 1 4 1 5 9 2 6 2 4 1 4 1 5 9 2 6 2 i 0 1 2 3 4 5 6 7 8 9 Q. Do you understand "coupon collector"? b[i] F T T F T T T F F T 8

Programming Exam 1 Part 2 Fall 2015 Solution public class Count2 public static void main(string[] args) int M = Integer.parseInt(args[0]); // no number higher than M - 1 boolean[] b = new boolean[m]; // true means index was input // loop to read input, count integers and fill boolean array int count = 0; while (!StdIn.isEmpty()) int val = StdIn.readInt(); b[val] = true; count++; // count distinct numbers int distinct = 0; for (int i = 0; i < M; i++) if (b[i]) distinct++; // output StdOut.println(distinct + " distinct values among " + count + " integers"); 9

Written Exam Logistics The first exam is on Thursday Oct. 18. Prep session (first half) later today. Prep session (second half) Tuesday Oct. 16. You don't all fit in this room. Pay attention and know where to go. Arrive early. No calculator/phone/computer/headphones Advice. Review lectures/reading. Try an old exam (untimed). Try another one (timed). Review a few more. 10

Example question: Basics Q. Do you understand types and Java's type conversion and precedence rules? Ex. ( Fall 2014 Question 1) Give the type and value of each of the following Java expressions, supposing that it is used as the argument of a println() call. (3 < 2) && (1 > 0) boolean FALSE "800" + 99 String 80099 800 + 99 + "A" String 899A 3 + (int) Math.random() int 3 (double)(3 / 2) double 1.0 3 / 2.0 + 2 / 5 double 1.5 (8 <= 2) (2e88 <= 88e2) boolean FALSE Integer.parseInt("8.5*2") ILLEGAL 11

Example question: Arrays Q. Do you understand basic properties and rules about Java arrays? Ex. ( Fall 2016 Question 2) Which of the following statements are true for Java arrays? Mark each statement as either TRUE or FALSE. An array can't simultaneously store both an element of type double and an element of type boolean. TRUE Once you create an array, you cannot change its type. TRUE You must access the elements in an array in sequential order, e.g., you cannot access a[5] until you have accessed a[0], a[1], through a[4]. If a[] is a boolean array of length 126, then the expression a[i] will evaluate arbitrarily to either true or false if the index i is equal to 126. If a[] and b[] are two arrays of length 2, then a == b is true if and only if both a[0] == b[0] and a[1] == b[1] are true. FALSE FALSE FALSE 12

Example question: Loops and conditionals Q. Can you figure out the effect of a simple Java program that uses while and if statements? Ex. ( Fall 2014 Question 2) Fill in the trace for just after each iteration of the outer for loop in this program: int[] a = new int[n]; a[0] = 1; for (int i = 1; i < N; i++) int sum = 0; for (int j = 0; j < i; j++) sum = sum + a[j]; a[i] = 1 + (2 * sum) / i; i sum a[i] 0 1 1 1 3 2 4 5 3 9 7 4 16 9 5 25 11 6 36 13 Write one line of code that could replace the body of the outer loop. a[i] = 2*i + 1; 13

Example question: Input and output Q. Do you understand basic ways of communicating with your programs? Ex. ( S2011 Q4) Give the results of invoking this program with the given commands. public class Q4 public static void main(string[] args) int curr = StdIn.readInt(); StdOut.print(curr + " "); int prev = curr; while (!StdIn.isEmpty()) curr = StdIn.readInt(); StdOut.print((prev + curr) / 2 + " "); prev = curr; StdOut.println(); % more input.txt 2 4 6 8 10 12 8 2 % java Q4 < input.txt 2 3 5 7 9 11 10 5 % java Q4 < input.txt java Q4 2 2 4 6 8 10 10 7 Note: It prints the first number, then the average of each number and its predecessor. 14

Mark your calendar Tuesday October 9: Practice programming exam Thursday October 11: PROGRAMMING EXAM Tuesday October 16: Written exam prep (part 2) Thursday October 18: WRITTEN EXAM 15