学生管理系统1.0
package main
import (
"fmt"
"os"
)
type student struct {
name string
id int
}
var allStudents map[int]*student
func ShowAllstudent() {
for k, v := range allStudents {
fmt.Println("学号:&d 姓名:%s\n", k, v)
}
}
func newStudent(id int, name string) *student {
return &student{
id: id,
name: name,
}
}
func AddStudent() {
var (
id int
name string
)
fmt.Print("请输入学号:")
fmt.Scanln(&id)
fmt.Print("请输入姓名:")
fmt.Scanln(&name)
newstu := newStudent(id, name)
allStudents[id] = newstu
}
func DeleteStudent() {
var (
deleteId int
)
fmt.Print("请输入学号:")
fmt.Scanln(&deleteId)
delete(allStudents, deleteId)
}
func main() {
allStudents = make(map[int]*student)
for {
fmt.Println("欢迎来到xx学生管理系统!")
fmt.Println("**************************")
fmt.Println("请选择要实现的功能")
fmt.Println()
fmt.Println("1.查看所有学生信息")
fmt.Println()
fmt.Println("2.增加新的学生信息")
fmt.Println()
fmt.Println("3.删除某个学生信息")
fmt.Println()
fmt.Println("4.退出!")
fmt.Println("**************************")
var choice int
fmt.Println("请输入序号:")
fmt.Scanln(&choice)
fmt.Printf("你输出的选项是:%d\n", choice)
switch choice {
case 1:
ShowAllstudent()
case 2:
AddStudent()
case 3:
DeleteStudent()
case 4:
os.Exit(1)
default:
fmt.Println("请输出1,2,3或4")
}
}
}