pls help me to answer 5 to 8 Programming Exercise (50 points) In this assignment
ID: 3813751 • Letter: P
Question
pls help me to answer 5 to 8
Programming Exercise (50 points) 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. 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 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] (Subtract 120 50) 70Explanation / Answer
6.The below functio is addding n imes so it is valid fr egative entries also
(define (Multiply num times)
(if (= times 1)
num
(+ num (Multiply num (- times 1)))))
;> (Multiply -100 3)
7.
;6th que
(define (Multiply num times)
(if (= times 1)
num
(+ num (Multiply num (- times 1)))))
;3rd ques
(define (Subtract a b)
(- a b))
;4th ques
(define (abs n)
(if(>= n 0)
n
(Subtract 0 n)))
(define (return a b)
(if (>= (abs a) b)
(+ 1 (return (Subtract (abs a) b) b))
0
)
)
;IntDivide
(define (IntDivide a b)
(if(< a 0)
(Subtract 0 (return a b))
(return a b)))
>(IntDivide -80 12)
8.
(define (DiffDivideLet x y) ;x=8 y=3
(let ((operand1 (IntDivide x y))) ;Let IntDivide value is stored in operand1
(let ((operand1 (Multiply operand1 y) ) (operand2 x)) ;Here let operand2 store the x value since end we have to find ;substrctn of x and remanaing value and operand1 will contain result of multiplyig the y i.e 3 with (8/3) value
(Subtract operand2 operand1)))) ;At end we subtract the 2 values
>(DiffDivideLet 8 3)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.