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

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)
}
}
}
}