-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-4.go
More file actions
58 lines (47 loc) · 1.44 KB
/
task-4.go
File metadata and controls
58 lines (47 loc) · 1.44 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"crypto/sha256"
"fmt"
"strconv"
"strings"
)
type Student struct {
rollnumber int
name string
address string
subjects[] string
}
func NewStudent(rollno int, name string, address string, sub[] string)*Student {
s := new(Student)
s.rollnumber = rollno
s.name = name
s.address = address
s.subjects = sub
return s
}
type StudentList struct {
list []*Student
}
func(ls *StudentList) CreateStudent(rollno int, name string, address string, sub[] string)*Student {
st := NewStudent(rollno, name, address, sub)
ls.list = append(ls.list, st)
return st
}
func main() {
student := new(StudentList)
student.CreateStudent(24, "Asim", "AAAAAA", []string {"PF", "AP", "COAL"})
student.CreateStudent(25, "Naveed", "BBBBBB", []string {"Eng", "Cal", "IS"})
for i:=0; i<2; i++{
var packed_str string
fmt.Printf("%s List %d %s\n", strings.Repeat("=", 25),i, strings.Repeat("=", 25))
fmt.Printf("Student roll no \t %v \n", student.list[i].rollnumber)
fmt.Printf("Student name \t\t %v \n", student.list[i].name)
fmt.Printf("Student address \t %v \n", student.list[i].address)
packed_str = strconv.Itoa(student.list[i].rollnumber) + student.list[i].name + student.list[i].address
for j:=0; j<len(student.list[i].subjects); j++{
fmt.Printf("Subject %v \t %v \n",j , student.list[i].subjects[j])
packed_str += student.list[i].subjects[j]
}
fmt.Printf("Student Hash \t %x \n", sha256.Sum256([]byte(packed_str)))
}
}