, , ,

[SOLVED] Csci 4230 – assignment 5

$25

File Name: Csci_4230_____assignment_5.zip
File Size: 244.92 KB

Categories: , , , Tags: , , ,
5/5 - (1 vote)

For this assignment you must write the following functions in OCaml:
1. Write a function called quadratic that takes three arguments representing the three coefficients a, b,
and c of a quadratic equation and uses the quadratic formula to calculate the two roots of the equation.
If the discriminant b
2 − 4ac is negative, raise an exception called No_Real_Roots. Otherwise return a
tuple containing the two roots, even if the roots are identical.2. Write a function called third that returns the third element of a tuple containing three items.
3. Write a recursive function called reverse that takes a list as an argument and returns a list containing
the items in the original list in reverse order. You may not use any built-in list functions to do this,
but you may use the @ operator to append two lists.4. Write a recursive function called member that takes an item and a list as arguments and returns true
if the item is in the list and false otherwise. Use pattern matching to determine if the list is empty or
not. You may not use any built-in list functions.5. Write a recursive function called union that takes two lists as arguments and returns a list containing
all items that appear in either list with no duplicates. You may assume that each or the arguments
contains no duplicates, but there may be items that appear in both lists. You may use the member
function defined in the previous problem, but you may not use any built-in list functions.6. Write a recursive function called intersect that takes two lists as arguments and returns a list containing all items that appear in both lists with no duplicates. The same assumptions and restrictions
apply as the previous problem.7. Write a recursive function called partition that takes a pivot item and a list as arguments, and returns
a tuple containing a list of items from the list that are less than the pivot and a list of items from the
list that are greater than or equal to the pivot. If the original list contains duplicate items then the
partitions should also contain duplicate items. If the original list is empty, both of the partitions should
be empty. You may not use any built-in list functions.8. Write a recursive function called quicksort that takes a list and sorts it by using the first item in the
list as a pivot, partitioning the remaining items using that pivot, sorting the partitions, and appending
the first partition to the pivot and the second partition. You may use the partition function from the
previous problem, but you may not use any built-in list functions.What to Hand In
Implement all of the functions described above in a source file called yourlastnameAssign5.ml with your
actual last name. Make sure to put your name, CSCI 4230, and Assignment 5 in the comments (comments
in OCaml start with (* and end with *)). Upload the source file to D2L to the dropbox called Assignment
5.

Shopping Cart

No products in the cart.

No products in the cart.

[SOLVED] Csci 4230 – assignment 5[SOLVED] Csci 4230 – assignment 5
$25