CS 214 Lab 4: Controlling Behavior: Repetition


Today's exercise involves using BNF to examine the syntax of the construct that provides repetitive execution in each of our four languages. Like last week, we will use BNF to solve the same problem in each of our languages, to compare their repetition constructs.

This week's problem is this: given three real values start, stop and increment, display a table of base-10 logarithms beginning at start, ending at stop at intervals of increment. For example, if start is 1, stop is 2, and increment is 0.5, then our program should display something like this:

   The logarithm of 1 is 0
   The logarithm of 1.5 is 0.176091
   The logarithm of 2 is 0.30103

Begin by making a new labs/04 directory for this lab exercise and copying the code skeletons LogTable.java, log_table.adb, logTable.clj, and logTable.rb. from the course directory into your new directory. Each of these skeletons provides a partial "program" to solve this problem, using the following simple algorithm:

   1. Get start, stop, and increment.
   2. For count = start to stop by increment:
         Display count and the logarithm of count
We will be implementing this algorithm in each of the four languages. Since step 2 of this algorithm uses a counting loop, our "program" will need to use whatever repetition construct is available for a counting loop in a given language.

As before, we will lead you through the process using Java, after which you will apply the same techiques to solve the problem in the other three languages. As usual, you should begin with the Java introduction, but the order in which you do the three exercises does not matter.

  1. Java Introduction
  2. Ada Exercise
  3. Clojure Exercise
  4. Ruby Exercise

Turn in. Each of the four parts requires you to create files containing source code and execution traces. When you have completed them, use cat to create a single file that contains all of your results:

   cat script.java script.ada script.clojure script.ruby > lab04-results
Then submit your work by copying that single file into your personal folder in /home/cs/214/current/:
   cp lab04-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name. The grader will access and grade your results from there.


Calvin > CS > 214 > Labs > 04
This page maintained by Joel Adams.