# Lab6 201903482 ```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. ***
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.
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: ℕ-&gt;Double
gps(integer ascore):Double
Purpose: gives the grade point for the percentage score ascore.
Precondition: ascore&gt;=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: ℕ-&gt; [Char]
lgs(integer ascore):Char
Purpose: gives the letter grade for the percentage score ascore.
Precondition: ascore&gt;=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-&gt;Char
lgg(Char agp):Char
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-&gt;Elems
unique(Elems lst):Elems
Purpose: which gives the unique scores in the list lst
Precondition: length (lst)&gt;=0
𝑖𝑠𝐼𝑛 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡 ) ≥ 1
𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ = 0
Postcondition: {
ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
unique
unique(lst)
78
𝑖𝑠𝐼𝑛 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡 ) ≥ 1
𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ = 0
{
ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
88
{
𝑖𝑠𝐼𝑛 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡 ) ≥ 1
𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ = 0
ℎ𝑒𝑎𝑑(𝑙𝑠𝑡): 𝑢𝑛𝑖𝑞𝑢𝑒 𝑡𝑎𝑖𝑙(𝑙𝑠𝑡) 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
e. occurs(ascore, lst)
occurs: Elem*Elems-&gt; ℕ
occurs(Elem ascore,Elems lst):Double
Purpose: determines the occurrence of the score ascore in the list lst
Precondition: (ascore ∈ lst) ᴧ ( length(lst)&gt;=0)
1 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ^𝑜𝑛(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
Postcondition: {𝑜 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙𝑠(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ⌃ 𝑜𝑓𝑓(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
𝑜 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
occurs
occurs(ascore, lst)
89
1 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ^𝑜𝑛(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
{𝑜 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙𝑠(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ⌃ 𝑜𝑓𝑓(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
𝑜 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
88
1 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ^𝑜𝑛(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
{𝑜 + 𝑜𝑐𝑐𝑢𝑟𝑠 (𝑡𝑎𝑖𝑙𝑠(𝑙𝑠𝑡)) 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ⌃ 𝑜𝑓𝑓(ℎ𝑒𝑎𝑑(𝑙𝑠𝑡))
𝑜 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
f. topstuds(n,lst)
topstuds:Elem*Elems-&gt;Elems
topstuds(Elem n,Elems lst ):Elems
Purpose: gives the top n students based on their scores in the list lst.
Precondition: (n&gt;=0) ᴧ (length(lst)&gt;=0)
Postcondition: {
𝑡𝑎𝑘𝑒 𝑛[𝑥|𝑥 &lt; −𝑙𝑠𝑡, 𝑥 &gt; 50] 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ≥ 6 ⌃𝑛 ≥ 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
g. botstuds(n,lst)
botstuds: ℕ x Elems-&gt;Elems
botstuds(Elem n ,Elems lst):Elems
Purpose: gives the bottom n students based on their scores in the list lst.
Precondition: (n&gt;=0) ᴧ (length(lst)&gt;=0)
Postcondition:{
𝑡𝑎𝑘𝑒 𝑛[𝑥|𝑥 &lt; −𝑙𝑠𝑡, 𝑥 &lt; 50] 𝑖𝑓𝑓 𝑙𝑒𝑛𝑔𝑡ℎ(𝑙𝑠𝑡) ≥ 1 ⌃𝑛 ≥ 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
```