***CREATE A SCHEME (R5RS) PROGRAM***** Write and test the following functions th
ID: 3883082 • Letter: #
Question
***CREATE A SCHEME (R5RS) PROGRAM*****
Write and test the following functions that deal with points and lines in the Cartesian plane. (a) (y-value x b m), a function of three parameters (an x value, a y-intercept b, and a slope m) that returns the y value of the line at that x, that is mx + b. (b) (points-slope x1 y1 x2 y2), a function of four parameters (the x and y values of two points) that calculates the slope of a line through those points (x_1, y_1) and (x_2, y_2). You may assume that the two points are distinct. (c) (points-intercept x1 y1 x2 y2), a function of four parameters (the x and y values of two points) that calculates the y-intercept of a line through points (x_1, y_1) and (x_2, y_2). You may assume that the two points are distinct. (d) (on-parallels? x1 y1 x2 y2 x3 y3 x4 y4), a function of eight parameters (the x and y values of four points), returns true if the line through points (x_1, y_1) and (x_2, y_2) is parallel to the line through points (x_3, y_3) and (x_4, y_4). You may assume that points (x_1, y_1) and (x_2, y_2) are distinct, as are (x_3, y_3) and (x_4, y_4).Explanation / Answer
a) (define (y-value x b m) (+ (* m x) b))
b) (define (points-slope x1 y1 x2 y2) (/ (exact->inexact (- y2 y1)) (- x2 x1) ))
c) (define (points-intercept x1 y1 x2 y2) (- y1 (* (points-slope x1 y1 x2 y2) x1) ) )
d) (define (on-parallels? x1 y1 x2 y2 x3 y3 x4 y4) (if (and (= (- x2 x1) 0) (= (- x4 x3) 0)) #t (if (or (= (- x2 x1) 0) (= (- x4 x3 ) 0)) #f (if (= (points-slope x1 y1 x2 y2) (points-slope x3 y3 x4 y4) ) #t #f ) )) )
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.