Question: This assignment consists of three F# exercises. The code for all exercises are to be included in a single file hw4.fsx. For each of the

This assignment consists of three F# exercises. The code for all exercises are to be included in a single file hw4.fsx. For each of the exercises, you are only required to write the provided functions. There is no additional global functionality. To test your functions, either: Test the functions using the interactive simulator. Add your own tests to the script (but be sure to comment them out before submission) Implementation Rules You may define and use additional functions as you find appropriate. Without prior approval from me, you may only use the subset of F# described in class. o In particular, you may NOT use F# system functions (such as min) or methods. o Even though they were mentioned in class, you are NOT allowed to use the methods in the List module such as List.map. Exercise 1 Write a function maxGrade that takes a list of floating-point tuples that represents grades for a student. The order of the tuple elements will be participation, assignment, midterm, and final exam. If the list is empty, return 0.0. Use pattern matching to complete the exercise.

Write a helper function that calculates the weighted grade and use it in maxGrade. Examples: > maxGrade [(90.0, 75.0, 82.5, 89.0);(85.5, 82.0, 72.5, 92.0)] ;; val it: float = 82.3 > maxGrade [(60.0, 70.0, 80.0, 90.0)] ;; val it : float = 77.0 Exercise 2

Write a recursive function makeAscend that takes a list of integers and ensures that the elements are in non-descending order by removing all the out-of-order elements.

Examples: > makeAscend [1; 4; 2; 7; 6; 3; 5; 9; 8] ;; val it: int list = [1; 4; 7; 9] > makeAscend [1; 4; 4; 0; 0; 6; 1; 8] ;; val it: int list = [1; 4; 4; 6; 8]

Exercise 3 Write the following binary search tree functions for a binary search tree of string-float pairs. Use the following type definition for a BST (copy this into your solution): // Tree definition for problem 3 type PairBST = | Empty | TreeNode of string * float * PairBST * PairBST Here is a sample tree diagram with the code that created the tree. > let bt1 = insert "juice" 3.99 Empty;; val bt1: PairBST = TreeNode ("juice", 3.99, Empty, Empty) > let bt2 = insert "cup" 1.25 bt1;; val bt2: PairBST = TreeNode ("juice", 3.99, TreeNode ("cup", 1.25, Empty, Empty), Empty) > let bt3 = insert "blanket" 12.50 bt2;; val bt3: PairBST = TreeNode ("juice", 3.99, TreeNode ("cup", 1.25, Empty, Empty), TreeNode ("blanket", 12.5, Empty, Empty))

> let bt4 = insert "table" 17.75 bt3;; val bt4: PairBST = TreeNode ("juice", 3.99, TreeNode ("cup", 1.25, Empty, Empty), TreeNode ("blanket", 12.5, Empty, TreeNode ("table", 17.75, Empty, Empty))) > let bt5 = insert "pen" 2.67 bt4;; val bt5: PairBST = TreeNode ("juice", 3.99, TreeNode ("cup", 1.25, Empty, TreeNode ("pen", 2.67, Empty, Empty)), TreeNode ("blanket", 12.5, Empty, TreeNode ("table", 17.75, Empty, Empty))) > search "cup" 1.25 bt5;; val it: bool = true > search "table" 2.67 bt5;; val it: bool = false > count (fun (s,f) -> f < 5) bt5;; val it: int = 3 > count (fun (x,y) -> x[1] = 'u') bt5;; val it: int = 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!