package main
import "fmt"
type Student_
struct {
id
int
name
string
age
int
score
float32
}
type Class_
struct {
class_name
string
students
[]*Student_
}
func (c
*Class_
) Delet_student(id
int){
stu
:=make([]*Student_
,0,200)
for i
,j
:=range c
.students
{
if j
.id
==id
{
continue
}
fmt
.Println(j
)
stu
=append(stu
,c
.students
[i
])
}
c
.students
=stu
}
func (c
*Class_
)show_all(){
for _,j
:=range(c
.students
){
fmt
.Println(j
.id
,j
.name
,j
.age
,j
.score
)
}
}
func(c
*Class_
) alter_student_information(id
int,name
string,age
int,score
float32){
for _,j
:=range c
.students
{
if j
.id
==id
{
j
.name
=name
j
.age
=age
j
.score
=score
}
}
}
func (c
*Class_
)add_stu(id
int,name
string,age
int,score
float32){
stu
:=&Student_
{id
,name
,age
,score
}
c
.students
=append(c
.students
,stu
)
}
func main
() {
p
:=Class_
{"1001",
make([]*Student_
,0,200),
}
p
.add_stu(10,"bosh",12,98.5)
p
.add_stu(11,"bosh1",13,98)
p
.add_stu(13,"bosh2",15,68)
p
.show_all()
fmt
.Println("删除11号学生")
p
.Delet_student(11)
p
.show_all()
}
运行结果
转载请注明原文地址:https://tech.qufami.com/read-19631.html