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

In this assignment, you will be learning Scheme through the use of Dr. Racket. W

ID: 3813712 • Letter: I

Question

In this assignment, you will be learning Scheme through the use of Dr. Racket. We would like to start with some basic concepts; trying to under prefix notation and the use procedure in Scheme. You will also implement nested procedures and recursive procedures. You may only use the procedures shown in the text and slides - not any of the additional library procedures in Scheme.

Using Dr. Racket to compute the following expressions.

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]

> (Subtract 120 50)

70

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.

You must use the Subtract procedure defined above.

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]

> (IntDivide 8 3)

2

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]

(ReadForIntDivide)

-25

4

-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]

You can use the built-in + operation.

You will need to account for negative values as well.

> (Multiply 8 3)

24

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]

> (DiffDivide 8 3)

2

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]

> (DiffDivideLet 8 3)

2

> (Subtract 120 50)

70

Explanation / Answer

1. directio num1-num2 calculation here
(define (Subtract num1 num2)
(- num1 num2))

> (Subtract 120 50)

2. Here we define abs fuctio to get value of the variables.the if we find that a is negative e return the IntDivide value with - sign ,the actual divsion is done in 'return' fuction
(define (abs n)
(if(>= n 0)
n
(- 0 n)))

(define (return a b)
        (if (>= (abs a) b)
                   (+ 1 (return (- (abs a) b) b))
0
)
)

(define (IntDivide a b)
(if(< a 0)
(- 0 (return a b))
(return a b)))

  
>(IntDivide -12 2)

3. Mutiplication is othing but adding the number times.so ecursively calling functio to add the number
(define (Multiply num times)
(if (= times 1)
      num
      (+ num (Multiply num (- times 1)))))
  
> (Multiply 100 3)