-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentData.jl
38 lines (33 loc) · 919 Bytes
/
StudentData.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright (c) 2022 Code Komali
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
module StudentData
export Student, students, sortedStudents, studentCompareFn
# Complex type
struct Student
name::String
rollno::String
cgpa::Float64
end
# instances of the complex type Student
students = [
Student("jack", "s2020123", 8.9),
Student("jill", "s2020124", 4.9),
Student("tom", "s2020125", 6.9),
Student("pip", "s2020126", 9.9),
Student("mark", "s2020127", 7.9)
]
# expected result after sorting students (descending) by CGPA
sortedStudents = [
Student("pip", "s2020126", 9.9),
Student("jack", "s2020123", 8.9),
Student("mark", "s2020127", 7.9),
Student("tom", "s2020125", 6.9),
Student("jill", "s2020124", 4.9)
]
# comparison function for student
function studentCompareFn(x::Student, y::Student)
x.cgpa > y.cgpa
end
end