-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-3.go
More file actions
45 lines (36 loc) · 937 Bytes
/
task-3.go
File metadata and controls
45 lines (36 loc) · 937 Bytes
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
package main
import (
"fmt"
"strings"
)
type Student struct {
rollnumber int
name string
address string
}
func NewStudent(rollno int, name string, address string)*Student {
s := new(Student)
s.rollnumber = rollno
s.name = name
s.address = address
return s
}
type StudentList struct {
list []*Student
}
func(ls *StudentList) CreateStudent(rollno int, name string, address string)*Student {
st := NewStudent(rollno, name, address)
ls.list = append(ls.list, st)
return st
}
func main() {
student := new(StudentList)
student.CreateStudent(24, "Asim", "AAAAAA")
student.CreateStudent(25, "Naveed", "BBBBBB")
for i:=0; i<2; i++{
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)
}
}