Advertisement
Gumanitariy

lab2\2

Nov 12th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.49 KB | None | 0 0
  1. // Part 2
  2.  
  3. // Load the data
  4. #load "one.fsx"
  5. //task 2
  6.  
  7. let groups =
  8.   Data.studs
  9.   |> Seq.map snd
  10.   |> Seq.distinct
  11.  
  12. let count g =
  13.   Data.studs |> Seq.filter (snd >> (=)g) |> Seq.length
  14.  
  15. let subjects = Data.subjs
  16. //--------------Part 1--------------------------------------------
  17. // Print the average grade for each subject
  18. let countGrade s =
  19.   Data.marks
  20.   |> Seq.filter (fun (x,y,z) -> y = s)
  21.   |> Seq.averageBy(fun (x,y,z) -> float z)
  22.  
  23. printfn "Average Grades"
  24.  
  25. subjects
  26. |> Seq.iter (fun (f,s) ->
  27.     printfn "Subject: %s, \t # Average Grade: %1.2f" s (countGrade f))
  28.  
  29. //--------------Part 1--------------------------------------------
  30. // For each group, print the number of students who failed the exam
  31. let countFailed g =
  32.   Data.marks
  33.   |> Seq.filter (fun (x,y,z) -> z = 2)
  34.   |> Seq.filter (fun (x,y,z) -> (Seq.exists(fun (name,group) -> name = x && group = g) Data.studs) )
  35.   |> Seq.length
  36.  
  37. printfn "\nFailed Students in Groups"
  38.  
  39. groups
  40. |> Seq.iter (fun g ->
  41.     printfn "Group: %d, # Failed students: %d" g (countFailed g))
  42.  
  43. //--------------Part 1--------------------------------------------
  44. // Find the number of failing students for each subject
  45. let countFailedForSubject s =
  46.   Data.marks
  47.   |> Seq.filter (fun (x,y,z) -> y = s)
  48.   |> Seq.filter (fun (x,y,z) -> z = 2)
  49.   |> Seq.length
  50.  
  51. printfn "\nFailing Students in Subjects"
  52.  
  53. subjects
  54. |> Seq.iter (fun (f,s) ->
  55.     printfn "Subject: %s, \t # Failed students: %i" s (countFailedForSubject f))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement