Question: Solution must be written in Haskell. Solution can't use functions that are not included in Prelude. 3. convert, sumGrades, and organize - 238 You are

Solution must be written in Haskell. Solution can't use functions that are not included in Prelude.

Solution must be written in Haskell. Solution can't use functions that are

not included in Prelude. 3. convert, sumGrades, and organize - 238 You

3. convert, sumGrades, and organize - 238 You are asked to write a program that will store and analyze the courses that college students transferred. The grades of transferred courses can be represented using different grading scales: 1. 4 point SCORE (e.g., 4,3,2,1,0) 2. LETTER grades (e.g., A, B, B, D, F) 3. PASS and FAIL grades You define the following Haskell datatype to represent the grades: data Grade = LETTER Char | SCORE Int | PASS | FAIL deriving (Show, Eq, Ord) (a) convert 38 Function "convert" converts a given a LETTER value to its equivalent SCORE value. For all other Grade values (i.e., PASS, FAIL, or SCORE), it will return the input value unchanged. For example: convert (LETTER 'A') returns 4 convert (LETTER 'B') returns 3 convert (LETTER 'C') returns 2 (LETTER 'D') returns 1 convert (LETTER 'F') returns 0 convert PASS returns PASS convert FAIL returns FAIL convert (SCORE 10) returns (SCORE 10) convert The type of the convert function should be convert :: Grade -> Grade (b) sumGrades - 10% Define a Haskell function sumGrades that takes a list of Grade values and returns the sum of all grades in that list as a SCORE value. You can assume that PASS and FAIL grades has no score. Your sumGrades function shouldn't need a recursion but should use a higher order function (map, foldr/foldi, or filter). You may define additional non-recursive helper functions. The type of the sumGrades function should be: sumGrades :: [Grade) -> Grade (Hint: You may filter out PASS and FAIL scores before you sum the grades.) Examples: > sumGrades (LETTER 'A', PASS , FAIL, SCORE 1, SCORE 2, SCORE 4, FAIL, PASS, LETTER 'D', LETTER 'C'] SCORE 14 > sumGrades [PASS, FAIL] SCORE 0 > sumGrades [] SCORE 0 (c) organize 10% Define a Haskell function sumGrades that organizes a list of courses into sublists according the scale of the course grades. The function takes a list of courses where each course is represented as a (String, Grade) tuple and it returns a nested list of (String, Grade) tuples. Your organize function shouldn't need a recursion but should use higher order functions. You may define additional helper functions which are not recursive. The type of the organize should be compatible with one of the following: organize :: [(a, Grade)] -> [[(a, Grade)]] Examples: > organize [("Cpt5355", LETTER 'A'), ("Cpt5499",PASS), ("EE499",FAIL), ("MATH216", SCORE 1), ("Cpts322", SCORE 4), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')] [[ ("MATH216", SCORE 1), ("Cpts322", SCORE 4)], [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')], [("Cpts499", PASS), ("EE 499", FAIL)]] > organize [("Cpts499", PASS), ("EE499",FAIL), ("MATH216", SCORE 1), ("Cpts322", SCORE 4)] [[ ("MATH216", SCORE 1), ("Cpts322", SCORE 4)], [], [("Cpts499", PASS), ("EE499", FAIL)]] > organize [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')] [[], [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')],[1] 3. convert, sumGrades, and organize - 238 You are asked to write a program that will store and analyze the courses that college students transferred. The grades of transferred courses can be represented using different grading scales: 1. 4 point SCORE (e.g., 4,3,2,1,0) 2. LETTER grades (e.g., A, B, B, D, F) 3. PASS and FAIL grades You define the following Haskell datatype to represent the grades: data Grade = LETTER Char | SCORE Int | PASS | FAIL deriving (Show, Eq, Ord) (a) convert 38 Function "convert" converts a given a LETTER value to its equivalent SCORE value. For all other Grade values (i.e., PASS, FAIL, or SCORE), it will return the input value unchanged. For example: convert (LETTER 'A') returns 4 convert (LETTER 'B') returns 3 convert (LETTER 'C') returns 2 (LETTER 'D') returns 1 convert (LETTER 'F') returns 0 convert PASS returns PASS convert FAIL returns FAIL convert (SCORE 10) returns (SCORE 10) convert The type of the convert function should be convert :: Grade -> Grade (b) sumGrades - 10% Define a Haskell function sumGrades that takes a list of Grade values and returns the sum of all grades in that list as a SCORE value. You can assume that PASS and FAIL grades has no score. Your sumGrades function shouldn't need a recursion but should use a higher order function (map, foldr/foldi, or filter). You may define additional non-recursive helper functions. The type of the sumGrades function should be: sumGrades :: [Grade) -> Grade (Hint: You may filter out PASS and FAIL scores before you sum the grades.) Examples: > sumGrades (LETTER 'A', PASS , FAIL, SCORE 1, SCORE 2, SCORE 4, FAIL, PASS, LETTER 'D', LETTER 'C'] SCORE 14 > sumGrades [PASS, FAIL] SCORE 0 > sumGrades [] SCORE 0 (c) organize 10% Define a Haskell function sumGrades that organizes a list of courses into sublists according the scale of the course grades. The function takes a list of courses where each course is represented as a (String, Grade) tuple and it returns a nested list of (String, Grade) tuples. Your organize function shouldn't need a recursion but should use higher order functions. You may define additional helper functions which are not recursive. The type of the organize should be compatible with one of the following: organize :: [(a, Grade)] -> [[(a, Grade)]] Examples: > organize [("Cpt5355", LETTER 'A'), ("Cpt5499",PASS), ("EE499",FAIL), ("MATH216", SCORE 1), ("Cpts322", SCORE 4), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')] [[ ("MATH216", SCORE 1), ("Cpts322", SCORE 4)], [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')], [("Cpts499", PASS), ("EE 499", FAIL)]] > organize [("Cpts499", PASS), ("EE499",FAIL), ("MATH216", SCORE 1), ("Cpts322", SCORE 4)] [[ ("MATH216", SCORE 1), ("Cpts322", SCORE 4)], [], [("Cpts499", PASS), ("EE499", FAIL)]] > organize [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')] [[], [("Cpts355", LETTER 'A'), ("Cpts321", LETTER 'D'), ("Math171", LETTER 'C')],[1]

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!