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

Programming Exercise (Graded) In this assignment, you will be learning Scheme th

ID: 3707467 • Letter: P

Question

Programming Exercise (Graded)

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

B) [10% Spec] Bind (define) each value in A - 5 above to its’ English text and then change the expression using the defined names. For example, the values in A - 1 would be replaced with names three, five, and seven, and the infix version would now read: (three + five - seven). This problem is to get you used to using (define ...)

C) [10% Spec] Define a procedure “Subtract” that takes parameters and returns the difference of them You can use the built-in “-“ to define your Subtract procedure.

D) [20% Spec] 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.

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.

E) [10% Spec] 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.

F) [10% Spec] 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.

G) [10% Spec] 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.

H) [10% Spec] Write a function/series of functions called explode that will take a string as a parameter and return a list containing the characters of the string. (Hint: think helper function)

I) [10% Spec] Create a function/series of functions called implode that will take a list as a parameter and return a string containing the list elements. (Hint: think helper function) (Double Hint: this is very much a re-write of H)

Grading of Programming Assignment

(1) Compile the code. If it does not compile you will receive a U on the Specifications in the Rubric

(2) The TA will read your program and give points based on the points allocated to each component, the readability of your code (organization of the code and comments), logic, inclusion of the required functions, and correctness of the implementations of each function.

Rubric:

What to Submit?

You are required to submit your solutions in a compressed format (.zip). Zip all files into a single zip file. Make sure your compressed file is labeled correctly - lastname_firstname11.zip.

For this home assignment, the compressed file MUST contain the following:

If multiple submissions are made, the most recent submission will be graded, even if the assignment is submitted late.

Explanation / Answer

(write "Problem A")
(newline)

(+ (+ 3 5) (- 7))

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

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

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

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

(newline)
(newline)
(write "Problem B")
(newline)
(define zero 0)
(define two 2)
(define three 3)
(define four 4)
(define five 5)
(define six 6)
(define seven 7)
(define eight 8)
(define ten 10)
(define twentyfive 25)

(+ (+ three five) (- seven))

(- (* two (+ eight five four)) twentyfive)

(- ten (+ (* three five) (+ two (* five zero))))

(* five (+ four (/ (+ (+ ten ten) (* five eight)) (+ ten two))))

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

(newline)
(newline)
(write "Problem C")
(newline)

(define Subtract
(lambda (x y)
    (- x y)
))

(Subtract 120 50)

(newline)
(newline)
(write "Problem D")
(newline)

(define IntDivide
(lambda (x y)
    (if (< (abs x) y)
        x
        (IntDivide (Subtract x y) y)
)))

(IntDivide 7 3)
(IntDivide 8 3)
(IntDivide 9 3)

(newline)
(newline)
(write "Problem E")
(newline)

(define ReadForIntDivide
(lambda ()
      (let ((x (read)))
        (let ((y (read)))
          (IntDivide x y)
))))

(ReadForIntDivide)

(newline)
(newline)
(write "Problem F")
(newline)

(define Multiply
(lambda (x y)
    (if (= y 1)
        x
        (+ x (Multiply x (- y 1)))
)))

(Multiply 8 3)

(newline)
(newline)
(write "Problem G")
(newline)

(define DiffDivide
(lambda (x y)
    (Subtract x (Multiply (IntDivide x y) y))
))

(DiffDivide 8 3)

(newline)
(newline)
(write "Problem H")
(newline)

(define DiffDivideLet
(lambda (x y)
(let* ((id (IntDivide x y))
         (m (Multiply id y))
        (s (Subtract x m)))
    s
)))

(DiffDivideLet 8 3)