Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 144
Introduction to Computer Science: Multimedia

Michael Goldwasser

Spring 2015

Dept. of Math & Computer Science

Homework Assignment 2

Control Structures

Due: 11:00am, Tuesday, February 10, 2015


Contents:


Overview

Topic: Control Structures
Related Reading: Notes/slides from class
Due: 11:00am, Tuesday, February 10, 2015

Note that homework assignments should be submitted in class as hard copy (although you are welcome to test your solutions with Processing).


Collaboration Policy

For this assignment, you must work individually.

Please make sure you adhere to the policies on academic integrity in this regard.


Problems to be Submitted (30 points)

  1. (6 points)

    Given the following definitions, what value and type do the following expressions evaluate to?

    int a = 2;
    int b = 5;
    float x = 2.0;      
    float y = 10.0;
    
    1) y * (b - a)
    2) 10 % b + x
    3) b / a * x

  2. (6 points)

    Translate the following while loop to an equivalent for loop:

    int n = 0;
    while (n < 50) {
      ellipse(n, n, 2*n, 2*n);
      n = n + 10;
    }      
    

  3. (9 points)

    Write statements that will change the background of the canvas to a random color if the current mouseX and mouseY are near the bottom left corner of the sketch window, and do nothing otherwise. (Hint: you can monitor the mouseX and mouseY variables from within draw, or use the mouseMoved() function, which is called whenver the mouse is moved over the canvas. That function provides both mouseX and mouseY as well as previous values pmouseX and pmouseY.)

    Here is an example:

  4. (9 points)

    Write a script that paints a grid over the canvas using horizontal and vertical lines. The resolution of the grid (i.e., the number of cells in each direction) should be determined by two int variables, r and c, where r specifies the number of rows and c specifies the number of columns.

    Here is an example sketch for values r=8 and c=5.

    Sample Grid


Michael Goldwasser
CSCI 144, Spring 2015
Last modified: Sunday, 08 February 2015
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit