Final Exam Winter 2013

Similar documents
What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username

Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.

Chapter 5. Condi.onals

Bits and Bytes. How do computers compute?

What is a variable? A named locajon in the computer s memory. A variable stores values

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

Chapter 8. More with classes Prac2ce with Zoog

Chapter 8. Classes and Objects

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Recall that creating or declaring a variable can be done as follows:

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

Conditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:

5.1. Examples: Going beyond Sequence

Methods (cont.) Chapter 7

A B C D CS105 03a Interaction

CISC 1600 Lecture 3.1 Introduction to Processing

Question 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels:

The way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

We will start our journey into Processing with creating static images using commands available in Processing:

EP486 Microcontroller Applications

CS 101 Functions. Lecture 15

Interaction Design A.A. 2017/2018

Chapter 12: Functions Returning Booleans and Collision Detection

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Loops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2

CSE120 Wi18 Final Review

CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions

CMPT-166: Sample Midterm

Module 01 Processing Recap. CS 106 Winter 2018

CISC 1600, Lab 3.1: Processing

Processing Assignment Write- Ups

Watch the following for more announcements

CISC 1600, Lab 2.1: Processing

Basic Computer Programming (Processing)

[ the academy_of_code] Senior Beginners

Interaction Design A.A. 2017/2018

Exploring Processing

(Inter)Ac*ve Scripts. Sta*c Program Structure 1/26/15. Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

CST112 Variables Page 1

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values

CS110 Introduction to Computing Fall 2016 Practice Exam 1

Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor

Introduction to Processing. Sally Kong

Using Methods. Writing your own methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut

ACTIVE PROCESSING Summary Learning Objectives How to Proceed Check your Understanding Learning Objectives 412

1 Getting started with Processing

CISC 1600, Lab 2.2: Interactivity in Processing

Variables. location where in memory is the information stored type what sort of information is stored in that memory

Iteration in Programming

CS 106 Winter Lab 03: Input and Output

Class Notes CN19 Class PImage Page

if / if else statements

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

CISC 1600, Lab 3.2: Interactivity in Processing

CS 307 Midterm 1 Fall 2007

void setup() { void draw() { draw a rectangle or ellipse wherever the mouse cursor is }

University of Cincinnati. P5.JS: Getting Started. p5.js

CSE 131 Introduction to Computer Science Fall Exam II

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

Solution Notes. COMP 151: Terms Test

CPSC Fall L01 Final Exam

An Introduction to Processing

+ Questions about Assignment 5?

Repetition is the reality and the seriousness of life. Soren Kierkegaard

Arrays. Array an ordered collec3on of similar items. An array can be thought of as a type of container.

PROGRAMMING. We create identity

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

Computer Graphics. Interaction

Variables One More (but not the last) Time with feeling

Khan Academy JavaScript Study Guide

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

Winter 2017 Feb 13 th, 2017 CS106A Midterm. Last Name: First Name: Sunet ID (eg jdoe): Section Leader / Grader:

Final Examination CS 125 Introduction to Computer Science Fall Hours

CISC 1600, Lab 2.3: Processing animation, objects, and arrays

int b = 2; for (int a = 0; a < 10 b < 20; a++) { a = a + b; b = b + a; }

Module 01 Processing Recap

Lesson Two. Everything You Need to Know. 4 Variables 5 Conditionals 6 Loops

Interaction Design A.A. 2017/2018

Sten-SLATE ESP. Graphical Interface

The Processing language. Arduino and Processing.

CS 106A, Lecture 14 Events and Instance Variables

CS111: PROGRAMMING LANGUAGE II

COS 126 Midterm 1 Written Exam Fall 2011

In this chapter: What is an array? Declaring an array. Initialization. Array operations using the for loop with an array. Arrays of objects.

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

Introduction to Processing

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

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

Review. Custom Objects. Comparing Declarations and Initializers Built PopGame. Classes Fields and Methods Instantiation using the "new" keyword

CMPT-166: Sample Final Exam Answer Key

Module 05 User Interfaces. CS 106 Winter 2018

Investigation: Triangle congruencies.

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Variables and Control Structures. CS 110 Eric Eaton

Transcription:

Final Exam Winter 2013 1. Which modification to the following program makes it so that the display shows just a single circle at the location of the mouse. The circle should move to follow the mouse but leave no trail just the one circle should be visible. // Insertion position 1 ellipse(mousex, mousey, 5, 5); // Insertion position 2 A. Insert at position 1 B. Insert at position 2 C. Either A or B will work D. Don t insert anything. The code is fine as is 2. Which answer best describes the behavior of this Processing sketch? int xpos, ypos; size(400,400); ypos = 0; xpos = 0; ellipse(xpos, ypos, 5, 5); ypos = ypos + 1; xpos = xpos + (1-yPos/(height/2)); 3. What is the value in Java of the expression 17%5? A. 0 B. 1 C. 2 D. 3 E. 7 4. What is the value in Java of the expression 17/5? A. 3 B. 3.4 C. 4 5. Add the missing line to the code below so it produces the image shown. int pos = 0; rect(pos, pos, 10, 10); A. translate(10,10); B. pos = pos + 10; C. either A or B D. neither A nor B 6. Which image is drawn by the following program? translate(50, 50); rotate(radians(45)); line(-100,0,100,0); translate(25, 0); rect(0,0,40,20); A. A ball moves from the upper left corner, diagonally to the lower right corner. B. A ball moves from the upper left corner, diagonally to the center, then stops and stays in the center. C. A ball moves from the upper left corner, diagonally to the center, then straight down to the bottom. D. A ball moves from the upper left corner, diagonally to the center, then diagonally to the lower left. E. A ball moves from the upper left corner, straight down the left side until half-way down then diagonally to the middle of the bottom.

7. What is printed during the drawing of the second frame of this program? int box1size = 200; int box2size = box1size/2; int box3size = box1size/4; println(box1size); println(box2size); println(box3size); // some code might go here to do the actual drawing box1size = box1size 1; A. 200 100 50 B. 199 100 50 C. 199 99.5 49.75 D. 199 99 49 8. Which answer applies to this program? int counter = 0; int xpos = width counter%width; fill(255,0,0); ellipse(xpos, 25, 5, 5); fill(0,255,0); ellipse((2*counter)%width, 75, 5, 5); counter = counter + 1; A. The red circle is moving faster than the green circle. B. The red one is moving right to left and the green one left to right. C. Both A and B. D. Neither of A nor B 9. What goes in the blank so the display is black when the mouse is left of the center and white when it is to the right of the center? A. mousex < 50 B. mousex > 50 if ( ) { C. mousex!= 50 background(0); 10. How many rectangles are drawn? int ypos = 0; while (ypos!= 50) { rect(ypos, ypos, 20, 40); ypos = ypos + 10; A. 0 B. 4 C. 5 D. 50 E. more than 50 11. How many points are drawn by the following program? A. 0 B. 2 C. 15 D. 40 E. more than 40 for (int i = 1; i <= 40; i = i + 1) { if (i % 15 == 0) point(i, i); 12. Which of the following is NOT specified for the formal parameters in a function (or method) definition? A. type B. name C. value D. position in the parameter list

The next set of four problems is an extended matching problem. Each problem shows a Processing sketch. Enter the letter that corresponds to the output. The possible choices are not all used and some may be used more than once. a. c. e. b. d. 13. Select the best choice from the list of choices A-E above for what this program displays. for (int row = 0; row < height; row = row + 20) { rect(row, row, 20, 20); 14. Select the best choice from the list of choices A-E above for what this program displays. for (int y = 0; y < height; y = y + 20) { for(int x = y; x < width; x = x + 20) { rect(x, y, 20, 20); 15. Select the best choice from the list of choices A-E above for what this program displays. for (int x = 0; x < height; x = x + 20) { for(int y = 0; y <= x; y = y + 20) { rect(x, y, 20, 20); 16. Select the best choice from the list of choices A-E above for what this program displays. for (int row = 0; row < height; row = row + 20) { rect(0, 0, width-row, height-row); 17. What expression can you put in the blank so this program shows a circle falling from the top center to the middle and then stopping when it reaches the center of the display staying there for 50 frames and then moving back up and off of the screen? int bally = 0; background(120); bally = bally + ; ellipse(width/2, bally, 20, 20); A. framecount/(height/2) B. framecount%(height/2) C. (1-(frameCount/(height/2))) D. (1-(ballY/(height/2))) E. bally/(height/2)

18. Which choice below will cause all of the values stored in the array data to be printed out in reverse order? int[] data = {22, 17, 95, 16, 103, -14, 95; // Choice A for (int i = data.length-1; i >= 0; i--) { print(data[i] + ); // Choice B for (int i = 0; i < data.length; i++) { print(data[data.length-1-i] + ); C. Both A and B will print all of the elements in reverse order. D. Neither A nor B will print all of the elements in reverse order 19. How many rectangles are drawn by the following Processing sketch? int i = 0; if (i < 100) { rect(i, i, 10, 10); i = i + 10; A. 0 B. 1 C. 10 D. 100 E. more than 100 20. How many times does this program print test? int constrainit(int val, int min, int max) { if (val < min) return min; else if (val > max) return max; println( test ); A. 0 return val; B. 1 C. 2 println(constrainit(10, 20, 30)); println(constrainit(40, 20, 30)); 21. Given the array declaration int[] scores new int[70]; fill in the blank so the print statement prints what is stored in the last element of the array: println( );? A. scores[69] B. scores[70] C. scores.length D. scores.last E. last(scores) 22. What is the second line printed by this program? A. a is now 123 B. a is now 456 C. a here is 456 D. It doesn t print anything. There is a syntax error involving the variable a. int a = 123; println( a is now + a); int a = 456; println( a here is + a);

23. What does the following program print? int x = 10; timestwo(x); println(x); A. 10, 20 B. 20, 10 C. 20, 20 void timestwo(int x) { x = x * 2; println(x); 24. What does the following program print? int x = 10; timestwo(); println(x); A. 10, 20 B. 20, 10 C. 20, 20 void timestwo() { x = x * 2; println(x); 25. Fill in the blank so that this function returns true if the circle at x1, y1 with radius r1, has collided with the circle at x2, y2, with radius r2. boolean collided(int x1, int y1, int r1, int x2, int y2, int r2) { return ; A. dist(x1, y1, x2, y2) <= r1+r2 B. abs(x1-x2) >= r1+r2 && abs(y1-y2) <= r1+r2 C. A and B will both work D. Neither A nor B work but one would be correct if the <= was >= E. Neither A nor B work but both would be correct if the <= was >= 26. What is the last number printed by the program to the right? A. 4 B. 12 C. 14 D. 16 E. 18 f2(f3(4)); void f1(int x){ println( f1 + x); void f2(int x){ println( x is + x); f1(x+2); int f3(int x){ println( f3 + x); return x+10;

27. What expression can you put in the blank so this program shows a circle falling from the top center to the middle and then moving diagonally towards the lower right corner? int ballx=50, bally=0; background(120); ballx = ballx + ; bally++; ellipse(ballx, bally, 20, 20); 28. Which of the images below could be produced by the code at the right? A. B C. Both A and B D. Neither A nor B 29. Which of the images below could be produced by the code at the right? A. framecount%50 B. (1-(ballY/50)) C. (1-(frameCount/100)) D. bally/50 E. ballx/50 framerate(10); int maxxy=0; if (maxxy > width) maxxy = 0; for(int y=0; y<maxxy; y=y+10) { for(int x=0; x<=y; x=x+10) { rect(x, y, 10, 10); maxxy = maxxy + 10; A. B C. Both A and B D. Neither A nor B 30. What expression goes in the blank so this program draws a red ball when the mouse is pressed and a black ball otherwise? drawball(mousex, mousey, ); A. mousepressed == true B. mousepressed C. both A and B work D.!mousePressed E. mousepressed == false 31. What does the following program print? int count = 0; int[] data = {10,0,-15,0,12,-7,0,14; for (int i = 0; i < data.length; i++) { if (data[i] <= 0) count++; println(count); void drawball(int x, int y, boolean red) { if (red) { fill(255,0,0); else { fill(0); ellipse(x, y, 40, 40); A. 1 B. 2 C. 3 D. 4 E. 5

32. What is the first value printed by the program to the right? A. -1 B. 1 C. 2 D. 8 E.10 33. What is the second value printed by the program to the right? A. -1 B. 0 C. 5 D. 7 E.10 int[] data = { 7, 10, 3, 10, 6, 7, 15, 10, 10 ; System.out.println(func1(10, data)); System.out.println(func1(7, data)); // look close this is not quite the // same function as before int func1(int x, int[] data) { for(int i = data.length-1; i >= 0; i--) if (data[i] == x) return i; return -1; 34. Which image is the result of the following program? for(int y=0; y<100; y=y+10) { for(int x=width-y-10; x<100; x=x+10){ rect(x, y, 10, 10); A B C D E 35. What does the following program print? int[] data = {10,20,30,40,50); for (int i = data.length-2; i >= 0; i--) { data[i+1] = data[i]; for (int i = 0; i < data.length; i++) { print(data[i] + ); A. 10 20 30 40 50 B. 50 40 30 20 10 C. 10 10 20 30 40 D. 20 30 40 50 50 E. 10 20 20 30 40 36. True or false, the output of these two code fragments is always the same? That is, for a given pair of values for x and y, these fragments will both print A or both print nothing. if (x < 20 && y < 30) { println( A ); if (x < 20) { if (y < 30) { println( A );

37. True or false, the output of these two code fragments is always the same? That is, for a given pair of values for x and y, these fragments will both print 100 or both print 0. int z = 0; if (x < 20 y < 30) { z = 100; println(z); int z = 0; if (x < 20) { z = 100; if (y < 30) { z = 100; println(z); The remaining questions are all about the following program // Create a class to represent a light bulb that can be // positioned, sized, given a color, and turned on and off as indicated // by the following usage of that class. Light light1, light2, light3, light4; size(400,400); light1 = new Light(25, 25); light2 = new Light(width-30, height-60, false); // set initially off light3 = new Light(width/2, height/2, 50); // specify the size light4 = new Light(30, height/2, 75, color(255, 0, 0));//set size and color light4.turnoff(); light1.show(); light2.show(); light3.show(); light4.show(); void mousepressed() { if (light1.clicked()) { light1.toggle(); if (light2.clicked()) { light2.toggle(); if (light3.clicked()) { light3.toggle(); if (light4.clicked()) { light4.toggle(); 38. How many methods NOT counting constructors must the Light class have for the program above? A. 1 B. 3 C. 4 D. 5 E. 6 39. How many constructors must the Light class have for the program above? A. 0 B. 1 C. 2 D. 3 E. 4 40. How many instance variables must the light class have? A. 2 B. 3 C. 4 D. 5 E. 6