Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Using Dr. Racket to compute the following expressions. [5 points] (1) 3 + 5 -

ID: 3814554 • Letter: 1

Question

1. Using Dr. Racket to compute the following expressions.                                          [5 points]

(1) 3 + 5 - 7

(2) 2 * ( 8 + 5 + 4 ) - 25

(3) 10 - ( ( 3 * 5 ) + ( 2 + ( 0 * 5 ) ) )

(4) 5 * ( 4 + ( ( ( 10 + 10 ) + ( 5 * 8 ) ) / ( 10 + 2 ) ) )

(5) ( ( ( ( ( ( 3 + 5 ) * ( 6 + 4 ) ) / 2 ) / 2 ) – 5 ) / 3) + ( ( ( ( 2 * 10 ) + ( 5 * 4 ) ) / 2 ) + ( 4 * 5 ) )

2. Bind (define) each value in 1.5 above to its’ English text and then change the expression using the defined names.                                                                            [5 points]
For example, the values in 1.1 should be replaced with names three, five, and seven, and the correct corresponding expression is (eight + two - ten).

3. Define a procedure “Subtract” that takes parameters and returns the difference of them You can use the built-in “-“ to define your Subtract procedure.            [5 points]

4. Define a recursive procedure called “IntDivide” that will compute the quotient of x divided by y. You must implement IntDivide procedure by a sequence of Subtract procedures.

(1) You must use the Subtract procedure defined above.

(2) You will need to account for negative values as well.

Hint: This will require a conditional and possibly the (abs x) procedure. You may not use the built-in division or quotient operators in this procedure definition.           [10 points]

5. Define a procedure “ReadForIntDivide” to read the two input values for the IntDivide procedure defined in the previous. This procedure takes no parameters and will pass an input value to the Square procedure.                                                                            [5 points]

6. Define a recursive procedure called “Multiply” that will compute the product of x times y. You must implement Multiply procedure by a sequence of additions.            [5 points]

(1) You can use the built-in + operation.

(2) You will need to account for negative values as well.

7. Define a procedure (DiffDivide x y) that will compute the following expression:
x - (x/y)*y. For example, if x = 8 and y = 3, then, 8 – (8/3)*3 = 2

You must use Subtract, IntDivide, and Multiply defined in the previous questions.      [5 points]

8. Re-implement the procedure (DiffDivide x y) and call it (DiffDivideLet x y). In this procedure, you must use let-form to bind all the procedures used in the definition: Subtract, IntDivide, and Multiply. You may name the local name whatever you’d like.              [10 points]

Explanation / Answer

1.

;1. 3+5-7

(- (+ 3 5) 7)

;2. 2*(8+5+4)-25

;wmathematic evaluation is frst bracket is simplified ,division,multiplicatn,addtn,subtractn

(- (* 2 (+ 8 5 4) ) 25)

;3. 10-((3*5)+(2+(0*5)))

(- 10 (+ (+ (* 0 5) 2) (* 3 5)))

;4. 5*(4+(((10+10)+(5*8))/(10+2)))

(* 5 (+ 4 (/ (+(+ 10 10) (* 5 8)) (+ 10 2))))

;5 ((((((3+5)*(6+4))/2)/2)-5)/3)+

;((((2*10)+(5*4))/2)+(4*5))

;first simplfy two lft ad rght brackets and add both

(+ (/ (- (/ (/ (* (+ 3 5) (+ 6 4)) 2) 2) 5) 3) (+ (/ (+ (* 2 10) (* 5 4)) 2) (* 4 5))

2.

;defining the english words for numbericals

(define one 1)

(define two 2)

(define three 3)

(define four 4)

(define five 5)

(define six 6)

(define seven 7)

(define eight 8)

(define nine 9)

(define ten 10)

(+ (/ (- (/ (/ (* (+ three five) (+ six four)) two) two) five) three) (+ (/ (+ (* two ten) (* five four)) two) (* four five))

3.(define (Subtract a b)

(- a b))

4.

(define (subtract a b)

(- a b))

(define (abs num)

(if(>= num 0) ;if numis >0 so return num

num

(subtract 0 num)));else return 0-n=-n negative value

(define (return n1 n2)

(if (>= (abs n1) n2)

(+ 1 (return (subtract (abs n1) n2) n2))

0

)

)

;IntDivide

(define (IntDivide a b)

(if(< a 0)

(subtract 0 (return a b))

(return a b)))

>(IntDivide -23 2)