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

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

Final Exam Winter 2013

Chapter 8. Classes and Objects

Chapter 5. Condi.onals

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

Chapter 8. More with classes Prac2ce with Zoog

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

Bits and Bytes. How do computers compute?

Methods (cont.) Chapter 7

CS 101 Functions. Lecture 15

Interaction Design A.A. 2017/2018

Processing Assignment Write- Ups

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

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

Interaction Design A.A. 2017/2018

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

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

CISC 1600, Lab 3.1: Processing

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

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

Basic Computer Programming (Processing)

CISC 1600, Lab 2.1: Processing

EP486 Microcontroller Applications

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

CMPT-166: Sample Midterm

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

If the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed.

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

CS 106 Winter Lab 03: Input and Output

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

Write a program that draws this image. The ligle squares are 5x5. The screen is the default 100x100. It doesn t change.

CS110 Introduction to Computing Fall 2016 Practice Exam 1

5.1. Examples: Going beyond Sequence

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

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:

Iteration in Programming

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

CSE120 Wi18 Final Review

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

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

CISC 1600, Lab 2.2: Interactivity in Processing

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

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

Introduction to Processing. Sally Kong

To specify the dimensions of the drawing canvas use the size statement: ! size( 300, 400 );

CISC 1600, Lab 3.2: Interactivity in Processing

Solution Notes. COMP 151: Terms Test

1 Getting started with Processing

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

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

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

CISC 1600 Lecture 3.1 Introduction to Processing

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

CPSC Fall L01 Final Exam

1. Complete these exercises to practice creating user functions in small sketches.

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

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

CMPT-166: Sample Final Exam Answer Key

Old 257 Exam #2s for Practice

if / if else statements

Computer Graphics. Interaction

CS 101 Spring 2007 Midterm 2 Name: ID:

Sten-SLATE ESP. Graphical Interface

An Introduction to Processing

Introduction to Processing

Investigation: Triangle congruencies.

Watch the following for more announcements

[ the academy_of_code] Senior Beginners

The Processing language. Arduino and Processing.

INTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen

+ Questions about Assignment 5?

EXAMINATIONS 2017 TRIMESTER 2

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

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

Chapter 12: Functions Returning Booleans and Collision Detection

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

EXAMINATIONS 2016 TRIMESTER 2

CS116X Midterm Review Winter 2015

Real Time Data Plotting

A B C D CS105 03a Interaction

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

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

Class #1. introduction, functions, variables, conditionals

Module 01 Processing Recap. CS 106 Winter 2018

Variables and Control Structures. CS 110 Eric Eaton

Exploring Processing

Evaluating Logical Expressions

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

Khan Academy JavaScript Study Guide

Unit 6 Quadratic Functions

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

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

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

THE JAVASCRIPT ARTIST 15/10/2016

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

ADVANCED LOOPS Summary Learning Objectives How to Proceed Check your Understanding Learning Objectives

1 Getting started with Processing

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

CS 106 Winter Lab 05: User Interfaces

Transform 1: Translate, Matrices

Transcription:

Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise. There are 21 problems and 25 points total. There are multiple versions of this exam. Don t be tempted to try and copy. The first set of nine 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. A black circle moves from right to left across the display. B. A black circle moves from left to right across the display. C. A black circle moves from top to bottom across the display. D. A black circle moves from bottom to top across the display. E. A black circle moves repeatedly back and forth (side-to-side) across the display. F. A black circle moves repeatedly up and down (top-to-bottom) across the display. G. A square area filled with small squares with the lower right corner of the filled area near (max(mousex,mousey), max(mousex,mousey)). H. A square area filled with small squares with the lower right corner of the filled area near (min(mousex,mousey), min(mousex,mousey)). I. A square area filled with small squares. The filled area starts with just one square then increases in size each frame until it fills an area determined by the current mouse location, then it starts over again with just one square. J. A black circle moves from the top center to the middle of the display and then moves diagonally to the lower right corner. K. A black circle moves from the bottom center to the middle of the display and then moves diagonally to the upper right corner L. A black circle moves in a straight line from the top center to the lower right corner. M. A black circle moves in a straight line from the bottom center to the upper right corner. N. R. V. O. S. W. P. T. Q. U.

1. Enter the best choice from the list of choices A-W above for what this program displays. line(0,90,100,90); rect(19,50,3,40); rect(79,50,3,40); rect(15,40,10,10); ellipse(80,50,20,20); 2. Enter the best choice from the list of choices A-W above for what this program displays. for (int row = 0; row < height; row+=20) { rect(row, row, 20, 20); 3. Enter the best choice from the list of choices A-W above for what this program displays. for (int row = 0; row < height; row+=20) { for(int col = 0; col <= width; col+=20) { rect(col, row, 20, 20); 4. Enter the best choice from the list of choices A-W above for what this program displays. for (int col = 0; col < width; col+=20) { for(int row = 0; row <= col; row+=20) { rect(col, row, 20, 20); 5. Enter the best choice from the list of choices A-W above for what this program displays. for (int row = 0; row < height; row+=20) { rect(0, 0, width-row, height-row); 6. Enter the best choice from the list of choices A-W above for what this program displays. int ballpos = 0; int ballsize = 10; fill(0); ellipse(width/2, ballpos, ballsize, ballsize); ballpos = ballpos + 1; 7. Enter the best choice from the list of choices A-W above for what this program displays. framerate(10); int limit=0; if (limit > mousex limit > mousey) limit = 0; for(int col = 0; col <=limit; col = col + 20) { for (int row = 0; row <= limit; row = row + 20) { rect(row, col, 20, 20); limit = limit + 20;

8. Enter the best choice from the list of choices A-W above for what this program displays. int ballpos = 0; int balldirection = 1; int ballsize = 10; fill(0); ellipse(width/2, ballpos, ballsize, ballsize); ballpos = ballpos + balldirection; if (ballpos < 0 ballpos > 100) { balldirection = balldirection*(-1); 9. Enter the best choice from the list of choices A-W above for what this program displays. int xpos, ypos; ypos = 0; xpos = width/2; int ballsize = 10; fill(0); ellipse(xpos, ypos, ballsize, ballsize); ypos = ypos + 1; xpos = xpos + ypos/(height/2); 10. What does the following program print? int[] data = new int[5]; for (int i = 0; i < data.length; i++) { data[i] = i*2; for (int i = data.length-1; i >= 0; i--) { print(data[i] + " "); 11. What does the following program print? int age = 92; String agebracket = "child"; if (age >= 65) { agebracket = "senior"; if (age >= 21) { agebracket = "adult"; if (age >= 16) { agebracket = "youth"; println(agebracket);

12. What does the following program print? void setup { int x = 6, y = 3; printproduct(x, y); x = 2; print(" "); printproduct(x + y, x); void printproduct(int x, int y) { print(x * y); 13. What does the following code fragment print? for (int i = 1; i <= 40; i = i + 1) { if (i > 35) print(i + " "); 14. (1 point) How many times does the following program print testing? ( put answer here) int i = 1; if (i < 20 ) { while (i <= 30) { println("testing"); i = i + 1; 15. What is printed by the following program?. func2(2); func2(func3(3)); void func1(int x) { println("func1 " + x); void func2(int x) { println("start"); func1(x*3); println("end"); int func3(int x) { println("func3 " + x); return x*10;

16. What does the following program print? int x = 10; it = x; printit(); it = 20; printit(); printit(); int it; void printit() { println(it); it = 0; 17. What does the following program print? int x = 10; printval(x); printval(20); println(x); void printval(int x) { println(x); x = 0; 18. (2 points) Assume that there is a global array of integers named data, write a code fragment that will count the number of zeros stored in the array and print out the count. 19. (2 points) Given the Rocket class from program 6 which includes instance variables xvel and yvel, write a method called safelanding() that could be added to the Rocket class and returns true if the rocket made a safe landing and false otherwise. Assume the rocket has landed and you are only deciding if it was a safe landing or not. A safe landing is one in which both the x and y velocities are between 0.4 and 0.4. class Rocket { float xvel, yvel; // most of the class is omitted and not needed for this question // put your safelanding method here

20. (2 points) Fill in the blanks so this program creates two balls. Ball1 should start at location (50,100) with zero y velocity and 0.2 x velocity. Ball2 should start at (300,100) with zero y velocity and -0.2 x velocity. The balls should then fall according to gravity as specified in the Ball class. They should each be 10 pixels in diameter. Ball ball1, ball2; float gravity = 0.1; size(400, 400); ball1 = ball2 = fill(255,0,0); class Ball { float x, y, xvel, yvel; int diam; Ball(float xstart, float ystart, float xv, float yv, int diameter) { x = xstart; y = ystart; xvel = xv; yvel = yv; diam = diameter; void update() { // check if hit the ground so need to reverse the velocity if (y > height-diam/2) { yvel = -yvel; // adjust position based on velocity y = y + yvel; x = x + xvel; // adjust the velocity - increasing due to gravity yvel = yvel + gravity; // always accelerate down // add some drag yvel = yvel*0.99; // draw the ball ellipse(x, y, diam, diam);

21. (2 points) Create a class to represent rectangles. A rectangle is specified (as with drawing them in Processing) by the coordinates of its upper left corner, its width, and its height. Give your class just enough functionality to make it work with the program below. The display() method should simply draw the rectangle with no change in fill or stroke. Rectangle[] boxes = new Rectangle[100]; size(400,400); for (int i = 0; i < boxes.length; i++) { boxes[i] = new Rectangle((int)random(width), (int)random(height), (int)random(10,40), (int)random(5,20)); for (int i = 0; i < boxes.length; i++) { fill(random(255), random(255), random(255)); boxes[i].display();