CS 3 (Garcia) Homework assignment 2 Spring 2001

Solutions to the following problems are due by 6pm on Friday, February 2nd. Deposit your solutions in the appropriate box in 283 Soda Hall box labeled with the lab section you will be attending next week.

Please put your name and lab section time on each page you hand in.


This assignment provides practice with various aspects of programmer-defined functions.


Chapters 3 and 4 of Simply Scheme.

Problems from Simply Scheme

Exercises 4.2, 4.3, 4.6 and 4.9.

One more problem

(You may need to read ahead a bit for this one. Read enough about if in Chapter 6 that you are comfortable with it if you haven't already.)

The Islamic calendar has twelve months, alternately 30 and 29 days as follows:

30 29 30 29 30 29 30 29 30 29 30 29

Fill in the framework below to complete the definition of the islam-day-of-year function. Islam-day-of-year takes two arguments, a month and a date in that month, e.g. 9 and 23 to mean the 23rd day of the 9th month, and should return the correspond­ing day of the year, 259 for the given example. You may assume that the arguments are legal values for a month and a date in that month.

; Given a legal month number (an integer between 1 and 12)

; and a legal date in that month, return the corresponding

; day in the Islamic year.

(define (islam-day-of-year month date)

(if (odd? month)

(+ ) ; odd-numbered month

(+ ) ) ) ; even-numbered month

Test your function on the following pairs of arguments:

1 1 3 1

1 30 11 30

2 1 12 1

2 29 12 29

Hand in a listing of your islam-day-of-year function, as well as a printout of an Interaction window with the results of the tests of your function indicated clearly.