Author: Moyanah Otukile Student ID: 201903482 Date: 2020/11/12 Version of work: Lab6 ***This piece of work was done under the University of Botswana policy. And I therefore affirm that this was individual work. *** Introduction to Haskell environment. See “getting started with Haskell” or “Writing your first Haskell program” Key tools: οΆ {editor, ghc interpretor} οΆ {:load, :cd, :!dir,:browse, … } ππππ‘(πππππ π, ππ ππ, πππ) π ππ£π_ππππ£ππ‘π(πππππ‘πππ) πβππ(: ππ, βΆ ! πππ, βΆ ππ, βΆ ππππ, βΆ ππππ€π π) π π’ππππ‘(ππππππππ, πππππππ) 1. a. gps(ascore) gives the grade point for the percentage score ascore. b. lgs(ascore) gives the letter grade for the percentage score ascore. c. lgg(agp) gives the letter grade for grade point agp. 2. Assume have the following: ο· A list L of students taking the CSI243 course indicating the scores for each piece of work for lab ο· A list L1 of students, from list L, who have passed at least 3 pieces of lab work. Assume a pass mark is a minimal score of 50% and labs hold each teaching week. a. unique(lst) which gives the unique scores in the list lst b. occurs(ascore, lst) which determines the occurrence of the score ascore in the list lst c. topstuds(n,lst) which gives the top n students based on their scores in the list lst. d. botstuds(n,lst) which gives the bottom n students based on their scores in the list lst. e. rev(lst) which gives the bottom n students based on their scores in the list lst. reverses the scores list lst. 3. Write a simple specification for each of the functions: a. gps(ascore) gps: β->Double gps(integer ascore):Double Purpose: gives the grade point for the percentage score ascore. Precondition: ascore>=0 Postcondition: 5 πππ ππ ππππ ≤ 80 4.5 πππ ≤ 75 4 πππ ≤ 70 3.5 πππ ≤ 65 3 πππ ≤ 60 2.5 πππ ≤ 55 2 ≤ 50 1.5 ≤ 45 1 ≤ 40 0.5 ≤ 35 { 0 ππ‘βπππ€ππ π gps gps(ascore) 70 5 πππ ππ ππππ ≤ 80 4.5 πππ ≤ 75 4 πππ ≤ 70 3.5 πππ ≤ 65 3 πππ ≤ 60 2.5 πππ ≤ 55 2 ≤ 50 1.5 ≤ 45 1 ≤ 40 0.5 ≤ 35 { 0 ππ‘βπππ€ππ π 87 5 πππ ππ ππππ ≤ 80 4.5 πππ ≤ 75 4 πππ ≤ 70 3.5 πππ ≤ 65 3 πππ ≤ 60 2.5 πππ ≤ 55 2 ≤ 50 1.5 ≤ 45 1 ≤ 40 0.5 ≤ 35 { 0 ππ‘βπππ€ππ π b. lgs(ascore) lgs: β-> [Char] lgs(integer ascore):Char Purpose: gives the letter grade for the percentage score ascore. Precondition: ascore>=0 Postcondition: ′π΄′ πππ ππ ππππ ≤ 80 ′π΅ + ′ πππ ≤ 75 ′π΅′πππ ≤ 70 ′π΅ − ′ πππ ≤ 65 ′πΆ + ′πππ ≤ 60 ′πΆ ′ πππ ≤ 55 ′πΆ − ′ ≤ 50 ′π· + ′ ≤ 45 ′π·′ ≤ 40 ′π· − ′ ≤ 35 { ′πΈ′ ππ‘βπππ€ππ π lg 89 lgs(ascore) ′π΄′ πππ ππ ππππ ≤ 80 ′π΅ + ′ πππ ≤ 75 ′π΅′πππ ≤ 70 ′π΅ − ′ πππ ≤ 65 ′πΆ + ′πππ ≤ 60 ′πΆ ′ πππ ≤ 55 ′πΆ − ′ ≤ 50 ′π· + ′ ≤ 45 ′π·′ ≤ 40 ′π· − ′ ≤ 35 { ′πΈ′ ππ‘βπππ€ππ π ′π΄′ πππ ππ ππππ ≤ 80 ′π΅ + ′ πππ ≤ 75 ′π΅′πππ ≤ 70 ′π΅ − ′ πππ ≤ 65 ′πΆ + ′πππ ≤ 60 ′πΆ ′ πππ ≤ 55 ′πΆ − ′ ≤ 50 ′π· + ′ ≤ 45 ′π·′ ≤ 40 ′π· − ′ ≤ 35 { ′πΈ′ ππ‘βπππ€ππ π 78 c. lgg(agp) lgg: Char->Char lgg(Char agp):Char Purpose: gives the letter grade for grade point agp. Precondition: agp !=null Postcondition: ′π΄′ πππ ππ ππππ ≤ 5 ′π΅+′ πππ ≤ 4.5 ′π΅′πππ ≤ 4 ′π΅ − ′ πππ ≤ 3.5 ′πΆ + ′πππ ≤ 3 ′πΆ ′ πππ ≤ 2.5 ′πΆ − ′ ≤ 2 ′π· + ′ ≤ 1.5 ′π·′ ≤ 1 ′π· − ′ ≤ 0.5 { ′πΈ′ ππ‘βπππ€ππ π lgg lgg(agp) 79 ′π΄′ πππ ππ ππππ ≤ 5 ′π΅+′ πππ ≤ 4.5 ′π΅′πππ ≤ 4 ′π΅ − ′ πππ ≤ 3.5 ′πΆ + ′πππ ≤ 3 ′πΆ ′ πππ ≤ 2.5 ′πΆ − ′ ≤ 2 ′π· + ′ ≤ 1.5 ′π·′ ≤ 1 ′π· − ′ ≤ 0.5 { ′πΈ′ ππ‘βπππ€ππ π 70 ′π΄′ πππ ππ ππππ ≤ 5 ′π΅+′ πππ ≤ 4.5 ′π΅′πππ ≤ 4 ′π΅ − ′ πππ ≤ 3.5 ′πΆ + ′πππ ≤ 3 ′πΆ ′ πππ ≤ 2.5 ′πΆ − ′ ≤ 2 ′π· + ′ ≤ 1.5 ′π·′ ≤ 1 ′π· − ′ ≤ 0.5 { ′πΈ′ ππ‘βπππ€ππ π d. unique(lst) unique: Elems->Elems unique(Elems lst):Elems Purpose: which gives the unique scores in the list lst Precondition: length (lst)>=0 ππ πΌπ π‘πππ(ππ π‘) βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) πππ πππππ‘β(ππ π‘ ) ≥ 1 πππ πππππ‘β = 0 Postcondition: { βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) ππ‘βπππ€ππ π unique unique(lst) 78 ππ πΌπ π‘πππ(ππ π‘) βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) πππ πππππ‘β(ππ π‘ ) ≥ 1 πππ πππππ‘β = 0 { βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) ππ‘βπππ€ππ π 88 { ππ πΌπ π‘πππ(ππ π‘) βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) πππ πππππ‘β(ππ π‘ ) ≥ 1 πππ πππππ‘β = 0 βπππ(ππ π‘): π’ππππ’π π‘πππ(ππ π‘) ππ‘βπππ€ππ π e. occurs(ascore, lst) occurs: Elem*Elems-> β occurs(Elem ascore,Elems lst):Double Purpose: determines the occurrence of the score ascore in the list lst Precondition: (ascore ∈ lst) ᴧ ( length(lst)>=0) 1 + ππππ’ππ (π‘πππ(ππ π‘)) πππ πππππ‘β(ππ π‘) ^ππ(βπππ(ππ π‘)) Postcondition: {π + ππππ’ππ (π‘ππππ (ππ π‘)) πππ πππππ‘β(ππ π‘) β πππ(βπππ(ππ π‘)) π ππ‘βπππ€ππ π occurs occurs(ascore, lst) 89 1 + ππππ’ππ (π‘πππ(ππ π‘)) πππ πππππ‘β(ππ π‘) ^ππ(βπππ(ππ π‘)) {π + ππππ’ππ (π‘ππππ (ππ π‘)) πππ πππππ‘β(ππ π‘) β πππ(βπππ(ππ π‘)) π ππ‘βπππ€ππ π 88 1 + ππππ’ππ (π‘πππ(ππ π‘)) πππ πππππ‘β(ππ π‘) ^ππ(βπππ(ππ π‘)) {π + ππππ’ππ (π‘ππππ (ππ π‘)) πππ πππππ‘β(ππ π‘) β πππ(βπππ(ππ π‘)) π ππ‘βπππ€ππ π f. topstuds(n,lst) topstuds:Elem*Elems->Elems topstuds(Elem n,Elems lst ):Elems Purpose: gives the top n students based on their scores in the list lst. Precondition: (n>=0) ᴧ (length(lst)>=0) Postcondition: { π‘πππ π[π₯|π₯ < −ππ π‘, π₯ > 50] πππ πππππ‘β(ππ π‘) ≥ 6 βπ ≥ 1 ππ‘βπππ€ππ π g. botstuds(n,lst) botstuds: β x Elems->Elems botstuds(Elem n ,Elems lst):Elems Purpose: gives the bottom n students based on their scores in the list lst. Precondition: (n>=0) ᴧ (length(lst)>=0) Postcondition:{ π‘πππ π[π₯|π₯ < −ππ π‘, π₯ < 50] πππ πππππ‘β(ππ π‘) ≥ 1 βπ ≥ 1 ππ‘βπππ€ππ π