Question
1. Using Dr. Racket to compute the following expressions. [5 points] 1.1 9 2 + 5 1.2 5 * ( 6 + 12 + 5
1. Using Dr. Racket to compute the following expressions. [5 points]
1.1 9 2 + 5
1.2 5 * ( 6 + 12 + 5 ) 25
1.3 7 * (( 5 - ( 1 * 3 )) + ( 2 * 4 ) )
1.4 3 * ( 4 + ( ( ( 6 * 6 ) + ( 6 * 6 ) ) / ( 10 + 2 ) ) )
1.5 ( ( ( ( ( ( 4 + 6 ) * ( 6 + 4 ) ) / 2 ) / 2 ) 5 ) / 2 ) + ( ( ( ( 4 * 5 ) + ( 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 Add that takes parameters and returns the sum of them.
[5 points]
|
4. Define a recursive procedure called Square that will compute the square amount of a value by additions. [15 points]
4.1 You must use the Add procedure defined above.
4.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
multiplication in this procedure definition. Note n2 = 1+3+5+ + (2n-1).
> (Square 5)
25
5. Define a procedure ReadForSquare to read a value for the Square procedure defined above.
This procedure takes no values and will pass an input value to the Square procedure. [5 points]
> (ReadForSquare - 5)
25
6. Define a procedure DiffSquares that will compute the difference between the square values of 2 inputs. You must implement the ReadForSquare procedure defined above. This procedure should never return a negative value, as it should return the absolute value. [10 points]
> (DiffSquares)
5
10
75
7. Re-implement the procedure Add and call it AddLet. In this procedure, you must implement let-form to bind values. You may name the variables whatever youd like. [5 points]
> (AddLet 60 40)
100
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started