You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4 KiB

3 years ago
package main
import (
"bufio"
"fmt"
"os"
)
/**
使
id
*/
type ExStudent struct {
ID, Age, Score, Name string
}
func main() {
var str string
exStuArr := make([]ExStudent, 0, 20)
in := bufio.NewScanner(os.Stdin)
for true {
fmt.Println("=== 学生管理系统 ===")
fmt.Println("* 1. 展示学生 *")
fmt.Println("* 2. 添加学生 *")
fmt.Println("* 3. 编辑学生 *")
fmt.Println("* 4. 删除学生 *")
fmt.Println("====================")
fmt.Println("请输入编号:")
if in.Scan() {
str = in.Text()
}
switch str {
case "1":
for _, v := range exStuArr {
fmt.Printf("ID: %v\nName: %v\nAge: %v\nScore: %v\n", v.ID, v.Name, v.Age, v.Score)
}
break
case "2":
exStu := ExStudent{}
fmt.Println("请输入ID:")
if in.Scan() {
exStu.ID = in.Text()
}
fmt.Println("请输入Age:")
if in.Scan() {
exStu.Age = in.Text()
}
fmt.Println("请输入Name:")
if in.Scan() {
exStu.Name = in.Text()
}
fmt.Println("请输入Score:")
if in.Scan() {
exStu.Score = in.Text()
}
exStuArr = append(exStuArr, exStu)
for _, v := range exStuArr {
fmt.Printf("ID: %v\nName: %v\nAge: %v\nScore: %v\n", v.ID, v.Name, v.Age, v.Score)
}
}
}
}