Assignment 3, due Sep 13

Part of the homework for 22C:60, Fall 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always write your name legibly as it appears on your University ID and on the class list! Due in class Monday the 13th because there is no class Friday the 10th.

Homework

  1. Background: A Java, C or C++ programmer could create a table of the squares of the integers from 0 to 8 by writing:
            int squares[]={0,1,4,9,16,25,36,49,64};
    

    Assume that integers are 32-bit values and assume that this table is a constant -- that is, that there will be no assignments to squares or to any of the table entries other than this initializer.

    The problem: Write SMAL code equivalent to this. (1 point)

  2. Background: Consider maintaining the table of squares as a list, where each item in the list consists of a pointer to the next item in the list and an integer value. The last item in the list has a null pointer in its next tiem field.

    The problem: Write SMAL code to represent a constant list of the first four squares, in ascending order, starting with the square of zero. (1 point)

  3. Background: Consider making an array of days of the week. A C programmer could write
            const char dayname[][]={ "Sunday", "Monday", "Tuesday",
                    "Wednesday", "Thursday", "Friday", "Saturday" };
    

    This is actually a constant array of pointers to null-terminated strings, despite the fact that the declaration looks like a two-dimensional array of characters.

    The problem: Write SMAL code to represent this. (1 point)