CS 2360 Fall 1995 Homework Assignment 1 Due no later than 8:00am, Monday, October 2, 1995 Here's your first LISP programming assignment. It's worth a total of 40 points. Make sure that you adhere to the constraints of the functional programming paradigm (e.g., access only information passed as parameters, return one value, no side effects, etc.). Use only those LISP functions that were introduced in class today (defun, list, sqrt, +, -, /, * -- I think that's all you'll need, but Lyman or Alex will tell us if you need more). Furthermore, remember that you're programming for people, not for the benefit of the computer. If you have working code, but we have to struggle to figure out how your code does what it does, you won't get many points. If your code doesn't work, but we think we can debug it easily, you'll get partial credit. If it works, and it communicates to us how it works, you'll do great. Here are the problems: 1) In baseball, a pitcher's earned run average is calculated by dividing the number of earned runs allowed by the number of innings pitched (giving an average number of earned runs allowed per inning), and multiplying that value by 9 (giving an average number of earned runs allowed per nine-inning game). Define a function called ERA which takes two arguments as input. The first argument is a number representing a pitcher's total earned runs allowed, and the second argument is a number representing that pitcher's total number of innings pitched. This function returns a number which is the pitcher's earned run average. examples: ? (era 1 9) 1.0 ? (era 9 1) 81.0 ? (era 3 5) 5.3999999999999995 2) Define a function called CIRCLE-STUFF which takes one argument, a number representing the radius of a circle, and returns a list of three numbers representing the radius, the area, and the circumference of the circle. example: ? (circle-stuff 4) (4 50.26548245743669 25.132741228718345) 3) The length of the hypotenuse of a right triangle is calculated by computing the square root of the sum of the squares of the lengths of the two sides of the triangle which meet at a right angle. Define a function called HYPOTENUSE which takes two arguments. The two arguments are numbers which represent the lengths of the two sides of a right triangle which meet at a right angle. The function returns a number representing the length of the hypotenuse of the the right triangle. examples: ? (hypotenuse 3 4) 5 ? (hypotenuse 9 16) 18.35755975068582 ? (hypotenuse 1 1) 1.4142135623730951 4) Today in class we went through the design and implementation of a LISP program for solving the quadratic equation. Prove to yourself, and to us, that our solution works by getting it to run on some Common LISP system. Of course, this means that you'll have to write the functions to compute the dreaded discriminant that we warned you about. examples: ? (quadratic 2 0 2) (#c(0.0 1.0) #c(0.0 -1.0)) [what is that #c thing? complex numbers!] ? (quadratic 2 2 0) (0.0 -1.0) --