package main
import (
"fmt"
"os"
)
var (
allstudent map[int64]*student
)
type student struct {
id int64
name string
}
func newStudent(id int64, name string) *student {
return &student{
id: id,
name: name,
}
}
func showstudent() {
for k, v := range allstudent {
fmt.Printf("学号是 %d name is %s", k, v.name)
}
}
func addStudent() {
var (
id int64
name string
)
fmt.Print("input the stu number")
fmt.Scanln(&id)
fmt.Print("input the stu name")
fmt.Scanln(&name)
student := newStudent(id, name)
allstudent[id] = student
}
func deleteStudent() {
var (
id int64
)
fmt.Print("input the stu number")
fmt.Scanln(&id)
delete(allstudent, id)
}
func main() {
allstudent = make(map[int64]*student, 480)
for {
fmt.Println(`
welcome to student management systemment
1. check all student
2. add new student
3.delete student
4. exit
`)
fmt.Println("please input your choice")
var choice int
fmt.Scanln(&choice)
switch choice {
case 1:
fmt.Print("check all stu")
showstudent()
case 2:
fmt.Printf("%s", "add new student")
addStudent()
case 3:
fmt.Println("delete student ")
deleteStudent()
case 4:
os.Exit(1)
default:
fmt.Println("defult")
}
}
}
go语言学生管理系统
最新推荐文章于 2023-02-08 16:09:53 发布