HW 2: Haskell Solution

$30.00 $24.00

Question 2: Select two of the options below and describe how you would modify your Haskell code to accomplish them. You do not need to modify your code, but your explanation should have sufficient detail that a classmate could accomplish the modification. •Handle student names of arbitrary length so that the whitespace reflects the actual…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Question 2:

Select two of the options below and describe how you would modify your Haskell code to accomplish them. You do not need to modify your code, but your explanation should have sufficient detail that a classmate could accomplish the modification.

Handle student names of arbitrary length so that the whitespace reflects the actual length of the longest name, but the table columns still line up.

Handle the “divide-by-zero” case where the GPA is undefined due to the student taking only zero-credit courses.

Print an error message if a student was enrolled in the same course more than once.

Print an error message if a course is listed with different numbers of credits for different students.

Have your program not crash on input that doesn’t match the specification.

For handling student names of arbitrary length, you could create a new function that takes in a list of StudentRecords and outputs a Int. This would find the length of the longest fifth element in the list. This could be accomplished by sorting it by the length and then picking the first in the list, or you could use map, length, and max to get the highest length. Then, you would use * in printf and call the function with the input data in the arguments.

For handling divide-by-zero cases, you could create a new function that takes in a two Doubles and outputs a Double. You also need to import Control.Exception This function would then utilize the ‘catch’ function then imported to handle the first argument divided by the second. Then, use ‘seq’ and return false, otherwise true (caught by \_).

1 of 1

HW 2: Haskell Solution
$30.00 $24.00