BU CAS CS 111: Introduction to Computer Science I

Spring 1998

Assignment 7 
(WAS due Friday 98.04.03 at 5 p.m. in room MCS 138)

(NOW due Monday 98.04.06 at 5 p.m. in room MCS 138)


  1. [4 points] Exercise 6.18, page 249.

  2. Modify the program given in this exercise as follows:
  3. [8 points] Exercise 6.23, page 251.

  4. The exercise says "Read commands from an array that contains them" (second sentence of second paragraph). Make this array to be one-dimensional of size 250, because we want you to test your program with lists of up to 250 commands. To test your program, read commands, store them in the array, and then execute them one by one. Assume that the turtle starts at position 0,0 with its pen up (as stated in the book) and, in addition, it is ready to move horizontally from left to right.

    We want you to use the list of commands given on page 251, except that we want you to cancel the 5th command:

    5,10         Move forward 10 spaces (or a number other than 10)

    and add the following new commands:

    10           Move forward by 0 space
    11           Move forward by 1 space
    12           Move forward by 2 spaces
    13           Move forward by 3 spaces
    etc.

    As an example, if you start at position 0,0 and you receive the command "2", you should put the "pen down" but leave no mark in position 0,0. If you next receive the command "12", you should move from position 0,0 to position 0,2 and, because the pen is down, you should leave a mark in positions 0,0 and 0,1 but not in position 0,2.

    Take into account the possibility of a command that moves the turtle outside the board (an error message should be issued and the session terminated). Turn in your program just after testing it on the data file:

    ~cs111/DataFiles/data_file_for_hwk_7_2

    You can run the (compiled) program "exercise_6.23_page_251.out" in directory ~cs111/DataFiles to see an output sample.


Assaf Kfoury Created: 98.03.27
Modified: 98.04.04