cs 341 spring 2024 homework 5 overview in this homework assignment you
Search for question
Question
CS 341, Spring 2024
Homework 5
Overview
In this homework assignment, you are going to write five functions in F#.
The code containing your five functions must be in a file named: hw05.fs. The code is to
be called from the F# code in a file named: main.fs. The file "main.fs" will act as the
testing code that will contain all of the code needed to verify correct execution of the
functions in the file "hw05.fs".
The initial code in "main.fs” only has one test case included. You are expected to create
additional test cases in "main.fs" to verify the functionality of your functions in "hw05.fs”.
Note that the version of “main.fs” that is part of the autograder code is fairly long and
contains quite a number of test cases. The test cases for the autograder will not be
released. You are encouraged to be very thorough when creating your own test cases.
The five functions that are to be written for this assignment are described below. Make
sure you follow the directions specified in the comments for each function regarding the
function's parameter(s), return value, implementation details, and helper functions.
Some of the functions may expect you to create helper functions to make sure they run
properly.
Exercise #1 - countBetween TR (tail recursive)
//
// countBetweenTR A BL
//
// Given a list L of integers, counts A < x < B x in L.
//
// Example: countBetweenTR 20 60 [20; 90; 50; 60; 45] => 2
//
// NOTE: write a tail-recursive version using a helper function;
// do not change the API of the original countBetween TR function.
// Exercise #2 - countBetween HO (higher-order approach)
//
// countBetweenHO A B L
//
// Given a list L of integers, counts A < x < B: x in L.
//
// Example: countBetweenHO 20 60 [20; 90; 50; 60; 45] => 2
//
// NOTE: write this using a higher-order approach, in
// particular using List.map and List.sum, or List.filter
// and List.length. Do not use other List functions.
//
Exercise #3 - highestExamAverage
//
// highestExamAverage LT
//
// Given a list of tuples of the form ("netid", [score; score;...]),
// computes each netid's average score as a real number and
// returns the netid of the student with the highest
// exam average. If more than one student has the same highest
// exam average, then return the netid of the first student in the
// list.
//
// Example:
// highestExamAverage [("sdeitz2", [100; 90;91]);
("psankar", [100;100])]
//
//
=> "psankar"
// NOTE: F# offers a function List.average L that computes the
// average of a list of real numbers. However, the list of
// scores in the tuple are integers, so in order to use
// List. average, you would first need to convert the integers to
// reals List.map float L would work nicely here.
//
---
// You can solve using recursion, or higher-order, or both;
// tail recursion is not necessary.
// Exercise #4 - subset
//
// subset SL
//
// Returns true if S is a subset of L, false if not.
//
// Examples: subset [3; 1; 2] [1; 4; 2;
0;
3] => yes
//
//
subset [2; 1; 3] [1; 4; 0;
subset [] []
2; 8]
=> no
=> yes
//
subset [] [1; 2; 3]
=> yes
//
subset [1..1000] [1..1000]
=> yes
//
// NOTE: you can solve using tail-recursion, or using a
// higher-order approach. Whatever you prefer. Beware
// that List.length is an O(N) operation, since it
// traverses the entire list and counts the elements.
//
// HINT: there are a variety of solutions. One idea
// is write a helper function "contains e L" that
// returns true if e is an element of L, and false
// if not. Then build on that to define subset. This
// leads to an O(N^2) solution, which is fine.
// Exercise #5 – pairwise
//
// pairwise L1 L2
//
// Given 2 lists L1 and L2, both the same length,
// merges the corresponding elements into pairs,
// returning a list of pairs.
//
// Example:
//
pairwise [1;3;5;7] [10;20;30;40]
// => [(1,10); (3,20); (5,30); (7,40)]
//
// You must solve using recursion; tail recursion is not necessary.
// Note: there is a F# library function named zip that
// does this operation.
// You may not use that function in your solution.
//
Requirements
In order to earn full points for this homework assignment, your code must meet the
following requirements:
• No variables (i.e. no use of the keyword mutable).
•
No loops. Instead, use recursion or higher-order functions, e.g. List.map, List.iter,
etc.
You must use recursion or higher-order programming as noted in the header
comments for each of the functions. Failure to use the proper approach for each
exercise will result in deduction of points after the assignment deadline.
Proper tail recursion is quite specific. Double check that any solutions you come up with
really do use tail recursion. In previous semesters, many students submitted
assignments that did in fact NOT implement proper tail recursion. Submission
Login to Gradescope.com and look for the assignment "Homework 05".
Submit your F# program file “hw05.fs". You have unlimited submissions. Keep in
mind we grade your last submission unless you select an earlier submission for
grading. If you do choose to activate an earlier submission, you must do so
before the deadline.
Add your name to the header comment and comment any functions you write!
No late submissions will be accepted for this assignment.
Academic Integrity
All work is to be done individually - group work is not allowed.
While we encourage you to talk to your peers and learn from them, this interaction must
be superficial with regards to all work submitted for grading. This means you cannot
work in teams, you cannot work side-by-side, you cannot submit someone else's work
(partial or complete) as your own, etc. The University's policy is available here:
https://dos.uic.edu/community-standards/
In particular, note that you are guilty of academic dishonesty if you extend or
receive any kind of unauthorized assistance. Absolutely no transfer of program code
between students is permitted (paper or electronic), and you may not solicit code from
family, friends, or online forums (e.g. you cannot download answers from Chegg). Other
examples of academic dishonesty include emailing your program to another student,
sharing your screen so that another student may copy your work, copying-pasting code
from the internet, working together in a group, and allowing a tutor, TA, or another
individual to write an answer for you.
Academic dishonesty is unacceptable, and penalties range from a letter grade drop to
expulsion from the university; cases are handled via the official student conduct process
described at the link above.