An accumulator is a procedure that is called repeatedly


Question 1

Submit your answer to this question as a PDF (Question1.pdf).

Part 1

Download Question1.rkt and draw an environment diagram representing the code within. Marks will be distributed as follows:

? Global definitions are correct
? All necessary frames are present
? All frames are arranged correctly (i.e. properly nested, etc)
? Definitions within the non-global frames are correct
? All code being called in the global frame and as the bodies of functions is represented correctly

Part 2

Explain what the lines
(point getx)
(point gety)

will display, and why, ensuring you trace through the environment diagram and as you explain.

Code Style and Testing

Refer to the below and the general "Assignment Do's and Don'ts" doc linked to on cuLearn.

? All code has been well indented and has been broken down into reasonably sized procedures (no single line should be too long; aim for about 80 characters each)
? Each procedure has been well documented (but not over-documented - don't just restate the code) with comments, including the purpose of the procedure, the expected inputs, and the expected output
? There is sufficient testing using check-expect and, at a minimum, no code is highlighted by DrRacket when the file is run

Question 2
An accumulator is a procedure that is called repeatedly with a single numeric argument and accumulates its arguments into a sum. Each time it is called, it returns the currently accumulated sum. Write a procedure make-accumulator that generates accumulators, each maintaining an independent sum . The input to make-accumulator will correctly specify the initial value of the sum; for example
(define A (make-accumulator 5))
(A 10)
15
(A 10)
25

Question 3

Write a procedure (make-queue) that produces independent first-in-first-out queue objects, using a message-passing style . For example:
(define queue1 (make-queue))
(define queue2 (make-queue))

Write procedures to manipulate queues. At a minimum:
1. (queue1 'empty?): boolean
2. (queue1 'enqueue! item): adds item to the queue
3. (queue1 'front): returns the next element of the queue that would be removed on dequeue
4. (queue1 'back): returns the last element of the queue that would be removed on dequeue (i.e. the most recent element added)
5. (queue1 'dequeue!): throws away the front element
6. (queue1 'print): prints some representation of the queue from front to back


Attachment:- ASSIGNMENT.rar

Solution Preview :

Prepared by a verified Expert
Software Engineering: An accumulator is a procedure that is called repeatedly
Reference No:- TGS0655765

Now Priced at $40 (50% Discount)

Recommended (93%)

Rated (4.5/5)