CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems

Similar documents
CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key for review problems

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key

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

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

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

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key for review problems

CIS 110: Introduction to Computer Programming

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

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

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

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

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

CSE 131 Introduction to Computer Science Fall Exam II

Programs, Statements, Variables

CIS Introduction to Computer Programming Spring Exam 1

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

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

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

Using Graphics. Building Java Programs Supplement 3G

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

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

CIS 110: Introduction to Computer Programming

CIS 110 Fall 2015 Introduction to Computer Programming 7 Oct 2015 Makeup Midterm Exam

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

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

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

Give one example where you might wish to use a three dimensional array

Syntax of Variable Declarations. Variables Usages as Expressions. Self-assignment Statements. Assignment. Scoping and Naming Rules

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

CIS 110: Introduction to Computer Programming

CSE 131 Introduction to Computer Science Fall Exam II

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

Prelim One Solution. CS211 Fall Name. NetID

Lecture 19: Recursion

Without fully opening the exam, check that you have pages 1 through 11.

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

CS 305j Midterm 1 Fall 2007

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

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

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

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

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

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

1 Getting started with Processing

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

CIS 110 Introduction to Computer Programming Summer 2016 Final. Recitation # (e.g., 201):

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

Title. Java Just in Time. John Latham. October 25, October 25, 2017 Java Just in Time - John Latham Page 1(0/0)

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

CS 305j Midterm 1 Fall 2008

AP Computer Science Unit 1. Writing Programs Using BlueJ

CSE 131 Introduction to Computer Science Fall Exam II

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

CS 161: Object Oriented Problem Solving

Introduction to Java Applications

CS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017

Final Examination CS 125 Introduction to Computer Science Fall Hours

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

Topic 6 Nested for Loops

CIS Introduction to Computer Programming Spring Exam 2

Computer Programming, I. Laboratory Manual. Final Exam Solution

Place your name tag here

CS 051 Homework Laboratory #2

CSE 131 Introduction to Computer Science Fall Final Exam

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

CS 312 Midterm 1 Spring 2013

1 Getting started with Processing

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

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

CS100J April 17, 2001

CS100B: Prelim 3 Solutions November 16, :30 PM 9:00 PM

Fall 2013 Program/Homework Assignment #2 (100 points) -(Corrected Version)

TWO-DIMENSIONAL FIGURES

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

Parameters. Repetitive figures. A solution? Parameterization. Declaring parameterized methods. Generalizing methods. Readings: 3.1

Introduction to Java Unit 1. Using BlueJ to Write Programs

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

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Creating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

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

ESC101 : Fundamental of Computing

CS 161: Object Oriented Problem Solving

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSc 328, Spring 2004 Final Examination May 12, 2004

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

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

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

CONDITIONAL EXECUTION

Exam Percentage: / 55 = %

1 Short Answer (15 Points Each)

AP Computer Science Unit 1. Writing Programs Using BlueJ

Transcription:

CIS 110 Introduction To Computer Programming October 5th, 2011 Exam 1 Review problems Scores: 1 2 3 4 5 6 Total (100 max)

CIS 110 Exam 1 Instructions You have 50 minutes to finish this exam. Time will begin when called by a proctor and end precisely 50 minutes after that time. If you continue writing after the time is called, you will receive a zero for the exam. This exam is closed-book, closed-notes, and closed-computational devices except for a one page sheet (8.5 by 11 ) of double-sided notes. When writing code, the only abbreviations you may use are for System.out.println and System.out.print as follows: System.out.println S.O.PLN System.out.print S.O.P Otherwise all code must be written out as normal. Please do not separate the pages of the exam. If a page becomes loose, please make sure to write your name on it so that we don t lose it, and use the provided staplers to reattach the sheet when you turn in your exam. If you require extra paper, please use the backs of the exam pages or the extra sheet paper provided at the end of the exam. Clearly indicate on question page where the graders can find the remainder of your work (e.g., back of page or on extra sheet ). If you have any questions, please raise your hand and an exam proctor will come to answer them. When you turn in your exam, you will be required to show ID. If you forgot to bring your ID, please talk to an exam proctor immediately. Good luck, have fun! 1

CIS 110 Exam 1 Cheat Sheet /** 1. For syntax, look at the format of the code presented in the questions * (unless otherwise stated, it is all syntactically correct code). */ // class declarations // method declarations public class <name> { public static <type> <name>(<params>) { <methods> <statements> /** 2. Useful methods for String objects */ charat(index) endswith(text) indexof(character) length() startswith(text) substring(start, stop) tolowercase() touppercase() // Returns the character at the given (zero-based) index. // Returns true if the string ends with the given text. // Returns the (zero-based) index of the given character. // Returns the length of the string. // Returns true if the string starts with the given text. // Returns the characters from the start index to just // before the stop index // Returns a new string with all lower case characters. // Returns a new string with all upper case characters. /** 3. Useful methods for Graphics objects */ drawline(x1, y1, x2, y2) // Draws a line between (x1, y1) and (x2, y2) drawoval(x, y, width, height) // Draws the outline of the largest oval that // fits in the specified rectangle. drawrect(x, y, width, height) // Draws the outline of the specified rectangle. drawstring(msg, x, y) // Draws the given text with its lower-left // corner at (x, y) filloval(x, y, width, height) // Fills the largest oval that fits in the // specified rectangle. fillrect(x, y, width, height) // Fills the outline of the given rectangle. setcolor(color) // Sets the graphics context to use the color. 2

Notes about this exam: Exam #1 covers all content covered so far in class from lectures, labs, homeworks, and the text (chapters 1 3 including 3G). The purpose of this exam is to test your algorithmic thinking skills rather than have you regurgitate facts about computer programming. To prepare for this exam, you should practice those skills by reviewing homeworks and doing practice problems discussed in section or found in the text. The exam is closed book, closed notes, and closed electronic devices. You may bring a single 8.5 11 sheet of double-sided notes to help jog your memory. In addition to your note sheet, we will include a sheet of commonly-used APIs so that you do not have to write them down. This cheat sheet appeared on the previous page. This practice exam introduces you to the types of problems that will be on the real exam. That way you can spend more time solving problems instead of trying to understand what the problem asks of you. That being said, while my goal is not to stray far from this format, the format of the actual exam may change slightly if necessary. I strongly recommend that you attempt this practice exam without looking at the answers. Afterwards, check your work, and then use the usual channels (e.g., Piazza, your TA, or myself) to resolve any lingering questions that you may have. 3

Expression Evaluating Machines 1. (10 points) Evaluate these Java expressions to their final values. (a) 10 * 3 + 4 / 2 (b) 3 / (double) 2 + 5 / 7 (c) 12 % 8-3 % 4 (d) "super" + 3 * 3 + "duper" + (8-5) (e) String s = "hello world!"; s.substring(2, 3) + ": " + (s.length() + 1) 4

Trace You A Loop 2. (10 points) Trace the execution of the following loops by filling in the provided tables. Each row of the table corresponds to the state of the program after executing the line marked HERE. You may skip any cases of the variables that do not reach execution of the line marked HERE. (a) for (int i = 0; i < 8; i += 2) { for (int j = 0; j < i / 2; j++) { System.out.println("*"); // HERE i j Output (each line) (b) for (int i = -1; i < 1; i++) { for (int j = 2; j > i; j--) { for (int k = 0; k < 1; k++) { System.out.println((i + j) * k); // HERE i j k Output (each line) 5

Method Mystery 3. (15 points) Write the output of this program in the space below. public static void f(int x, String y, int z) { System.out.println(y + " ; " + z + " ; " + x); public static int g(int n) { n--; n *= n + 2; return n; public static void main(string[] args) { int x = 0; String y = "forty-two"; int z = 1; f(z, y, x); f(x, "zero", z); f(z, y, z); f(x, "hello", g(5)); f(g(1), "bye", g(g(2))); 6

Patterns, Patterns, Patterns 4. (20 points) Consider the following ASCII picture: *- +=*-- +=+=*--- +=+=+=*---- (a) What is the form of each line (i.e., what is the pattern of characters on each line)? (b) For each chunk of characters you identify, give a formula for the number of chunks on each line in terms of the row number i. You may choose to number the first row either 0 or 1. (c) Finally, write a method, drawshape() that draws the above diagram in terms of the formulae that you derived. 7

Parameterization 5. (20 points) (a) Write a method, drawfigure, that takes a Graphics object as input and draws the following figure to that Graphics object. The figure consists of three parts: A circle of radius 50. Its anchor point is (0, 0). A square of width 100. Its anchor point is (50, 0). A horizontal line of length 150. Its left endpoint is at (0, 50). (b) Parameterize drawfigure further so that you can draw the figure anywhere on the screen. The figure should remain the same size, but the caller of drawfigure should be able to pass in an (x, y) pair to move the anchor of the figure (which is its upper left-hand corner). You may produce the new drawfigure method below or simply change your answer to the previous part to become parameterized. 8

Gonna Fly Now 6. (25 points) Write a method sillyprint that takes a parameter n and writes out the numbers from 1 to n with the following format: ][1][][2][][][3][... ][n][ Where the numbers are surrounded by square brackets in a pattern. For reference, here is the execution of sillyprint(7). ][1][][2][][][3][][][][4][][][][][5][][][][][][6][][][][][][][7][ Hint: Decompose the problem, writing a separate, well-named method, for each subproblem. And then combine all those methods in the definition of sillyprint to arrive at the final result. 9