CSC 160 Fall 2005 Homework 2
Assigned Sept 6, extended to WEDS Sept 21
Read Chapter
2 of the
textbook (pages 5 to 21).
Section 2.1 Numbers and Arithmetic
Using Dr. Scheme, evaluate the following expressions:
1. (+ 4 2)
2. (- 37 55)
3. (/ 108 12)
4. (* 3.5 6.9)
5. (+(- 2002 1965) (- 1999 1966))
6. (/(+(- 2002 1965) (- 1999 1966)) 2)
7. (*(-(+ 22 12) (- 30 17)) 3)
8. (expt 10 3)
9. (remainder 92 11)
10. (remainder (+ 37 55) (- 108 97))
Save the interactions window as HW2(LastName)sec1.scm
Section 2.2 Variables and Programs
Write a program in Scheme to calculate the number of miles traveled, given
the speed (in miles per hour) and the time traveled (in hours). The
formula is:
Distance (in miles) = Speed (in miles per hour) * Time Traveled (in
hours)
Save the definitions window as HW2(LastName)sec2.scm
Section 2.3 Word Problems
Develop the function, total-inches. The function consumes a length
represented by two numbers: the first a number of feet, and the second a
number of inches. The function produces the total length in inches.
(Hint: There are 12 inches in a foot.)
Save the definitions window as HW2(LastName)sec3.scm
Section 2.4 Errors
Complete Exercise 2.4.1 (Write down each of the three error messages.
Explain in one sentence what those error messages mean.)
Give an example of a run-time error. (Do not give one that was already
mentioned in class or the textbook.)
Give an example of a logical error. (Do not give one that was already
mentioned in class or the textbook.)
Include this in the body of your email.
Section 2.5 Designing Programs
Write the contract, purpose, and header for a function that computes the
area of a rectangle given its length and width. Then, write three
examples for the behavior of this program.
Include this in the body of your email.
Submitting this Assignment
Send an email to
Wittenstein@adelphi.edu.
Include your answer to questions 2.4 and 2.5 in the body of the email.
Then attach the files that answer questions 2.1, 2.2, and 2.3.
Be sure to include your FIRST and LAST name!
Grading
Each of the five sections is worth 20 points, for a total of 100
points.
Last Modified: 9/8/05