(基于Go)简易版学生管理系统

在学习Go语言基础后,为了巩固语言基础,我将用Go语言开发一个简易的学生管理系统,以此来简单地整合一下自己近期所学的知识!

下面就开始我Go语言的第一个管理系统的编写吧~

需求分析

该简易版的学生管理系统主要是以管理员视角来执行程序中所编写的相关功能。当然我们学生管理系统最基本的功能当然离不开基本的增删查改功能啦~
下面是我对该系统简单流程实现分析图~

设计分析

本次简易管理系统的编写主要分为了两个go文件

  • student.go
  • main.go

student.go

学生文件中创建了两个结构体(student、studentMaps),并在其中分层设计了5个功能业务,即如下

  • 查询所有学生信息(show)
  • 查询单个学生信息(ownshow)
  • 添加学生信息(add)
  • 修改学生信息(modify)
  • 删除学生信息(deletestu)

main.go

main文件中主要就是我们的主界面设计啦,就没啥子好讲的啦~

源码展示

main.go

package main

import (
   "fmt"
   "os"
)

//声明学生管理员对象
var instu studentMaps

func main() {
   systemmhead()
   instu = studentMaps{
      stuMgs: make(map[string]student,100),
   }
   for true {
      fmt.Println("**************************************")
      fmt.Println(`
            1.Access all student information
            2.Single query for student information
            3.Add student information
            4,Modify student information
            5.Delete student information
            6.Quit
      `)
      fmt.Println("Plese input your choose:")
      var i int8
      fmt.Scanln(&i)
      fmt.Printf("Your choose:%d\n",i)
      switch i {
      case 1:
         instu.show()
      case 2:
         instu.ownshow()
      case 3:
         instu.add()
      case 4:
         instu.modify()
      case 5:
         instu.deletestu()
      case 6:
         os.Exit(1)
      default:
         fmt.Println("Please enter the correct command!")

      }
   }
}

查询所有学生信息(show)

func (s studentMaps) show()  {
   //添加排序功能
   stuID := make([]string,0,len(s.stuMgs))
   for i := range s.stuMgs{
      stuID = append(stuID,i)
   }
   sort.Strings(stuID)
   for i ,v :=range stuID{
      fmt.Printf("number:%d\n    id:%v\n    name:%v\n    age:%v\n    class:%v\n",i+1,v,s.stuMgs[v].name,s.stuMgs[v].age,s.stuMgs[v].class)
   }
}

查询单个学生信息(ownshow)

//单个查询学生信息
func (s studentMaps) ownshow() {
   var(
      newid int64
   )
   fmt.Println("Enter the student ID number you want to query:")
   fmt.Scanln(&newid)
   strID := fmt.Sprintf("%d",newid)
   _,v := s.stuMgs[strID]    //v值为true或者false
   if !v {
      fmt.Printf("There is no student with%v\n",newid)
   } else {
         fmt.Printf("id:%v\n",s.stuMgs[strID].id)
         fmt.Printf("name:%v\n",s.stuMgs[strID].name)
         fmt.Printf("age:%v\n",s.stuMgs[strID].age)
         fmt.Printf("class:%v",s.stuMgs[strID].class)
      }
   }

添加学生信息(add)

//添加学生信息
func (s studentMaps) add()  {
   var (
      newid int64
      newname string
      newage int8
      newclass string
   )
   fmt.Print("Please enter the student id you want to add:")
   fmt.Scanln(&newid)
   fmt.Print("Please enter the name of the student you want to add:")
   fmt.Scanln(&newname)
   fmt.Print("Please enter the age of the student you want to add:")
   fmt.Scanln(&newage)
   fmt.Print("Please enter the class to which you want to add students:")
   fmt.Scanln(&newclass)
   strID := fmt.Sprintf("%d",newid)
   _,v := s.stuMgs[strID]    //v值为true或者false
   if v{
      fmt.Printf("%v already exists\n",strID)
   } else {
      newstu := student{
         id : newid,
         name : newname,
         age: newage,
         class: newclass,
      }
      //创建student类型对象对stuMgs赋值
      s.stuMgs[strID] = newstu
      fmt.Println("This student information has been added!")
   }
}

修改学生信息(modify)

//修改学生信息
func (s studentMaps) modify()  {
   var(
      newid int64
      newname string
      newage int8
      newclass string
   )
   fmt.Print("Please enter the student ID you want to modify:")
   fmt.Scanln(&newid)
   strID :=fmt.Sprintf("%d",newid)
   _,v := s.stuMgs[strID]
   if !v{
      fmt.Printf("%v does not exist\n",strID)
   } else {
      fmt.Print("Please enter the name of the student you want to modify:")
      fmt.Scanln(&newname)
      fmt.Print("Please enter the age of the student you want to modify:")
      fmt.Scanln(&newage)
      fmt.Print("Please enter the class you want to modify:")
      fmt.Scanln(&newclass)
      newstu := student{
         id: newid,
         name: newname,
         age: newage,
         class: newclass,
      }
      s.stuMgs[strID] = newstu
      fmt.Println("The student information has modify!")
   }

}

删除学生信息(deletestu)

//删除学生信息
func (s studentMaps) deletestu() {
   var(
      newid int64
   )
   fmt.Print("Please enter the student ID you want to delete:")
   fmt.Scanln(&newid)
   strID :=fmt.Sprintf("%d",newid)
   _,v := s.stuMgs[strID]
   if !v{
      fmt.Printf("%v does not exist\n",strID)
   } else {
      delete(s.stuMgs,strID)
      fmt.Println("The student information has been deleted!")
   }

}

运行结果

这就是我在学习Go基础后做出来的一个简易的学生管理系统啦~比较简陋,还望大佬们见谅 ~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小新没有蜡笔️

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值