0% found this document useful (0 votes)
13 views

Programming Assignment

The document provides instructions for an Asteroid programming assignment with three problems. Students are asked to rewrite functions using multi-dispatch and recursion. They must paste their code into the submission structured as indicated with section headers and formatting. Code will be run with the Asteroid -F switch.

Uploaded by

nks8jhpjgg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programming Assignment

The document provides instructions for an Asteroid programming assignment with three problems. Students are asked to rewrite functions using multi-dispatch and recursion. They must paste their code into the submission structured as indicated with section headers and formatting. Code will be run with the Asteroid -F switch.

Uploaded by

nks8jhpjgg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Note: The following are programming problems. No paper-and-pencil submission allowed.

In
order to get full credit for this assignment you must copy and paste here you working
Asteroid code for the entire assignment, in this sequence:
-- Your Name (type your own name, not "Your Name!")
(two empty lines)
-- Problem 1:
(one empty line)
Your code for problem 1
(two empty lines)
-- Problem 2:
(one empty line)
Your code for problem 2
(two empty lines)
-- Extra Credit: (this is optional)
(one empty line)
Your code for the extra credit
You must format the headings as comments. Asteroid has only single-line comments,
beginning with a double hyphen as shown. Brightspace will probably mangle your line
spacing, but if you start like this, it will make it fairly easy for us to find your work. We're not
doing this as a quiz because you can't set a quiz question to 0 points (i.e., the extra credit).
Remember: All your programs for this assignment must run under Asteroid 2.0.1 with the -F
switch. That is, 'asteroid -F <program_file>'.

Problem 1. (10 points) Given the following Asteroid program that squares the values on a list
and returns the squared values as a list,
Rewrite the function 'square' as a recursive function using multi-dispatch (Note, full credit
only if your solution utilizes multi-dispatch). Test your function on the following lists, using
assert: [1,2,3] and [0, -1, -2]. (The correct answers are [1,4,9] and [0,1,4] respectively.)
(Rubric: 4 points for multi-dispatch solution/asteroid -F, 3 points for each successful test
case)

Problem 2. (10 points) Given the following Asteroid program that returns true if the value
'm' can be found on input list 'input' otherwise it returns false,

Rewrite the function 'member' as a recursive function in multi-dispatch fashion and show
that your program works for the two test cases: member([1,2,3],2) and member([1,2,3],5);
you can use the same assert statements shown in the imperative/iterative form. (Rubric: 4
points for multi-dispatch/asteroid -F, 3 points for each successful test case)

Extra Credit. (10 points) Consider the following Asteroid program that computes the average
of a list of values and returns that average,
Rewrite this program as a functional program. It can contain multiple functions (think
mergesort we discussed in class). Test your program with the test case average([1,2,3]) == 2.
In order to get full credit your functions have to be written in multi-dispatch style and your
program has to be able to be interpreted with 'asteroid -F'.

Deliverables. Paste your code into this submission structured as indicated at the top. This
will help us find your work and give you maximum credit!

Tip: If you use hd() and/or tl() where you could have used pattern matching on the function
parameters, you might lose a point or two for inelegance and not taking advantage of the
new techniques discussed in class.

You might also like