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 5

Functions and Recursion

Due: 11:00am, Thursday, April 30, 2015


Contents:


Overview

Topic: Strings
Related Reading: Portions of Ch. 5 and Ch. 8
Due: 11:00am, Thursday, April 30, 2015

Note that homework assignments should be submitted in class as hard copy (although you are welcome to test your solutions with Processing, given that both problems are very tangible programming challenges).


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)

Preface: With understanding of the relevant documentation, you should be able to predict the results for these questions, but you may also choose to try some of these out in Processing to determine the outcome.

  1. (15 points)

    The book's stock market visualizer made use of Processing's map() function, which is used to extrapolate a value that was originally expressed within one range, to its corresponding value in another range. (See for example its use on page 169.) Its formal signature, as discussed in Processing's online reference, is

          float map(float value, float start1, float stop1, float start2, float stop2)
          
    As an example, the call map(25, 0, 100, 200, 400) should return 250.0, while map(5, 20, 10, 200, 400) should return 500.0. (Note well that the initial value need not be strictly within the original range.) For the function to be well defined, you may assume that start1 and stop1 are not the same value.

    Your task, once you understand the desired behavior, is to provide a self-contained implementation of such a map function. The body of your function implementation should not include any calls to other functions, but instead should revert to the underlying arithmetic to determine the answer.

    Hint: Consider the absolute gap between start1 and stop1, the gap between start2 and stop2, and the gap between value and start1.

  2. (15 points)

    When demonstrating recursion in lecture, we left a parting challenge to implement what is known as Sierpinski's Triangle. For this homework question, we wish to have you complete that challenge. You do not need to provide the complete Processing program in your solution; we are only interested in your implementation of a recursive function drawTriangle() having the following signature:

          void drawTriangle(float x0, float y0, float x1, float y1, float x2, float y2)
          
    For simplicity, you may assume that those points are oriented so that (x0,y0) is the top vertex of the triangle, that (x1,y1) is the bottomleft vertex, and (x2,y2) is the bottomright vertex.


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