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

Similar documents
CSE 142 Sample Midterm Exam #2

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

Sample Midterm Exam #2

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

CSE 142, Winter 2007 Final Exam. Name:

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CSE 142, Spring 2009, Final Exam

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

CSE 142 Sample Midterm Exam #3

CSc 110 Sample Midterm Exam #1

CSE 142, Autumn 2010 Final Exam Wednesday, December 15, Name:

CSE 142 Sample Midterm Exam #3

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules:

1. An operation in which an overall value is computed incrementally, often using a loop.

CSE142 Sample Midterm Autumn 2018

Name CIS 201 Midterm II: Chapters 1-8

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

CSE142 Sample Midterm, Winter 2018

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

Read and fill in this page now. Your instructional login (e.g., cs3-ab): Your lab section days and time: Name of the person sitting to your left:

Arrays. What if you have a 1000 line file? Arrays

CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010

CONDITIONAL EXECUTION: PART 2

CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009

Problem Description Earned Max 1 CSS 20 2 PHP 20 3 SQL 10 TOTAL Total Points 50

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

CSE 373, Winter 2013 Final Exam, Tuesday, March 19, Good luck! You can do it!

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.

CSE142 Midterm Autumn This exam is divided into eight questions with the following points: # Problem Area Points Score

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

CSE 154, Autumn 2012 Final Exam, Thursday, December 13, 2012

CIS Introduction to Computer Programming. 5 October 2012 Midterm

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

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

Read and fill in this page now

Midterm Review Session

Problem Description Earned Max 1 HTML / CSS Tracing 20 2 CSS 20 3 PHP 20 4 JS / Ajax / JSON 20 5 SQL 20 X Extra Credit 1 TOTAL Total Points 100

New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

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

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

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

Building Java Programs

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

Do not turn to the next page until the start of the exam.

CSE 143: Computer Programming II Autumn Sample Solutions

Building Java Programs

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Problem Description Earned Max 1 HTML / CSS Tracing 20 2 CSS 20 3 PHP 20 4 JS / Ajax / JSON 20 5 SQL 20 X Extra Credit 1 TOTAL Total Points 100

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

CS 305j Midterm 2 Fall 2006

CSE 143: Computer Programming II Spring 2015 Final Exam Solutions

Problem Description Earned Max 1 PHP 25 2 JavaScript/DOM 25 3 Regular Expressions 25 4 SQL 25 TOTAL Total Points 100

Programming Logic and Design Sixth Edition

ECSE 321 Assignment 2

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Condi(onals and Loops

Building Java Programs

University of Massachusetts Amherst, Electrical and Computer Engineering

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

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

CS 112 Introduction to Programming

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

Problem Description Earned Max 1 PHP 25 2 JavaScript / DOM 25 3 Regular Expressions 25 TOTAL Total Points 100. Good luck! You can do it!

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

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

Final Exam. COMP Summer I June 26, points

IB Event Calendar Please check regularly for updates Last Update: April 30, 2013

CSE 131 Introduction to Computer Science Fall Exam II

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

McGill University Faculty of Science School of Computer Science. MIDTERM EXAMINATION - Sample solutions. COMP-250: Introduction to Computer Science

Problem Points Score Grader Total 75

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

CS 101, Spring 2016 March 22nd Exam 2

CS 3L (Clancy) Solutions and grading standards for exam 1

Common Mistakes with Functions. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

CSCI 1226 Sample Midterm Exam

CSE 1223: Exam II Autumn 2016

CSE 115. Introduction to Computer Science I

CIS Fall 2012 Midterm, 7 June 2012, Answer Key. Miscellaneous

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

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

CSE 143 Lecture 10. Recursion

CSE 303 Midterm Exam

Announcements. Lab 03 inbase late submissions Midterm #1 Friday. Project 2 is posted. Covers everything through basics of OOP

CSE 142 Sample Final Exam #2

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Transcription:

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007 Name: Section: Student ID #: TA: Rules: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor calls for papers. This test is open-book/notes. You may not use any computing devices of any kind including calculators. Unless otherwise indicated, your code will be graded on proper behavior/output, not on style. You do not need to write any import statements in your exam code. Please do not abbreviate any code on your exam, such as writing S.o.p for System.out.println. If you enter the room, you must turn in an exam and will not be permitted to leave without doing so. You must show your Student ID to a TA or instructor for your submitted exam to be accepted. Good luck! Score summary: (for grader use only) Problem Description Earned Max 1 Expressions 15 2 Parameter Mystery 20 3 While Loop Simulation 15 4 Assertions 15 5 Programming 20 6 Programming 15 TOTAL Total Points 100 NOTE: There is not an extra credit question on this exam. 1 of 6

1. Expressions (15 points) For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in "quotes"). Expression 3 + 4 * 5 / 2 13 % 5 + 43 % (11 % 3) 1.5 * 3.0 + 25.0 / 10.0 5 / 2 + 123 / 10 / 10.0 5 + 2 + "(1 + 1)" + 4 + 2 * 3 Value 2. Parameter Mystery (20 points) At the bottom of the page, write the output produced by the following program, as it would appear on the console. public class ParameterMystery { public static void main(string[] args) { String p = "cause"; String q = "support"; String r = "troops"; String support = "hillary"; String cause = "rudy"; troops(p, q, r); troops(q, r, p); troops(support, p, cause); troops(r, "p", support); troops(q, "cause", q); public static void troops(string r, String p, String q) { System.out.println(q + " gave " + r + " to the " + p); 2 of 6

3. While Loop Simulation (15 points) For each call below to the following method, write the value that is returned: public static int mystery(int x) { int a = 1; int c = 0; while (x > 0) { a = x % 2; if (a == 1) { c++; x = x / 2; return c; Method Call mystery(2); mystery(-1); mystery(7); mystery(18); mystery(43); Value Returned 3 of 6

4. Assertions (15 points) For each of the five points labeled by comments, identify each of the following assertions as either being always true, never true, or sometimes true / sometimes false. // Counts number of "coin tosses" until we get heads 3 times in a row. public static int threeheads() { Random rand = new Random(); int flip = 1; int heads = 0; int count = 0; // Point A while (heads < 3) { // Point B flip = rand.nextint(2); // flip coin if (flip == 0) { // heads heads++; // Point C else { // tails // Point D heads = 0; count++; // Point E return count; Fill in each box of the the table below with one of the following words: ALWAYS, NEVER or SOMETIMES. (You may abbreviate these choices as A, N, and S as long as you write legibly.) Point A Point B Point C Point D Point E flip == 0 heads == 0 flip > heads 4 of 6

5. Programming (20 points) Write a static method named monthapart that accepts four integer parameters month1, day1, month2, and day2, representing two calendar dates. Each date consists of a month (1 through 12) and a day (1 through the number of days in that month [28-31]). The method returns true if the dates are at least a month apart and false otherwise. Dates are defined to be exactly a month apart if their day values are the same and their months differ by 1. For example, January 20 and February 20 are exactly one month apart, and July 16 and August 16 are exactly one month apart. Note that it does not matter exactly how many days the given months have. For example, the following dates are all considered to be at least a month apart from 9/19 (September 19): 2/14, 7/25, 8/2, 8/19, 10/19, 10/20, and 11/5. The following dates are NOT at least a month apart from 9/19: 8/20, 9/1, 9/25, 10/1, 10/15, and 10/18. Note that the first date could come before or after, or be the same as, the second date. Assume that all parameter values passed are valid. Sample calls: monthapart( 6, 14, 9, 21) should return true, because June 14 is at least a month before September 21 monthapart( 4, 5, 5, 15) should return true, because April 5 is at least a month before May 15 monthapart( 4, 15, 5, 15) should return true, because April 15 is at least a month before May 15 monthapart( 4, 16, 5, 15) should return false, because April 16 isn't at least a month apart from May 15 monthapart( 6, 14, 6, 8) should return false, because June 14 isn't at least a month apart from June 8 monthapart( 7, 7, 6, 8) should return false, because July 7 isn't at least a month apart from June 8 monthapart( 7, 8, 6, 8) should return true, because July 8 is at least a month after June 8 monthapart(10, 14, 7, 15) should return true, because October 14 is at least a month after July 15 5 of 6

6. Programming (15 points) Write a static method named sequencesum that prints terms of the following mathematical sequence: 1 1 1 1 1 1 + + + + + +... 2 3 4 5 6 ( also written as 1 i =1 i ) Your method should accept a real number as a parameter representing a maximum limit, and should repeatedly add and print terms of the sequence until the overall sum of terms meets or exceeds the maximum limit that was passed. For example, if your method is passed the value of 2.0, you should print terms of the sequence until the sum of all those terms is at least 2.0. The following output would result from the call sequencesum(2.0); 1 + 1/2 + 1/3 + 1/4 = 2.083333333333333 (Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed any value less than 1.0, no output should be produced. You must match the format of the output shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls: Calls sequencesum(0.0); sequencesum(1.0); sequencesum(1.5); Output 1 = 1.0 1 + 1/2 = 1.5 Call sequencesum(2.7); Output 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 = 2.7178571428571425 6 of 6