收藏 分销(赏)

C#控制台实现模拟学生管理系统.doc

上传人:s4****5z 文档编号:8754659 上传时间:2025-03-01 格式:DOC 页数:5 大小:148.50KB 下载积分:10 金币
下载 相关 举报
C#控制台实现模拟学生管理系统.doc_第1页
第1页 / 共5页
C#控制台实现模拟学生管理系统.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
C#控制台模拟学生管理系统 最终运行效果 添加学生 删除学生 修改学生 代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SGMS { class Program { static void Main(string[] args) { List<Student> lstStudent = new List<Student>(); bool flag = true; while (flag) { Console.WriteLine("------------------------------------------------"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("使用提示(按键-操作):A-添加 D-删除 C-修改 L-查看"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("------------------------------------------------"); ConsoleKey ck = Console.ReadKey(true).Key; switch (ck) { case ConsoleKey.A: { //Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("请输入学生相关信息"); //Console.ForegroundColor = ConsoleColor.Gray; Student stu = new Student(); Console.Write("学号:"); stu.stuNo = Console.ReadLine().Trim(); Console.Write("姓名:"); stu.stuName = Console.ReadLine().Trim(); Console.Write("性别:"); stu.stuSex = char.Parse(Console.ReadLine().Trim()); Console.Write("年龄:"); stu.stuAge = short.Parse(Console.ReadLine().Trim()); lstStudent.Add(stu); Console.WriteLine("添加成功"); break; } case ConsoleKey.D: { if (lstStudent.Count == 0) { Console.WriteLine("系统还未添加任何学生信息"); } else { Console.Write("请输入要删除的学生的学号:"); string no = Console.ReadLine().Trim(); for (int i = 0; i < lstStudent.Count; i++) { if (lstStudent[i].stuNo == no) { lstStudent.Remove(lstStudent[i]); Console.WriteLine("删除成功"); break; } if (i == lstStudent.Count - 1) Console.WriteLine("抱歉!系统中没有这个学号"); } } break; } case ConsoleKey.C: { if (lstStudent.Count == 0) { Console.WriteLine("系统还未添加任何学生信息"); } else { Console.Write("请输入要修改的学生的学号:"); string no = Console.ReadLine().Trim() ; for (int i = 0; i < lstStudent.Count; i++) { Student item = lstStudent[i]; if (item.stuNo == no) { Console.Write("学号:"); item.stuNo = Console.ReadLine().Trim(); Console.Write("姓名:"); item.stuName = Console.ReadLine().Trim(); Console.Write("性别:"); item.stuSex = char.Parse(Console.ReadLine().Trim()); Console.Write("年龄:"); item.stuAge = short.Parse(Console.ReadLine().Trim()); lstStudent[i] = item; Console.WriteLine("修改成功!"); break; } if (i == lstStudent.Count - 1) Console.WriteLine("抱歉!系统中没有这个学号"); } } break; } case ConsoleKey.L: { if (lstStudent.Count == 0) Console.WriteLine("系统还未添加任何学生信息"); else { Console.WriteLine("学号\t姓名\t性别\t年龄"); foreach (Student s in lstStudent) { Console.WriteLine("{0}\t{1}\t{2}\t{3}",s.stuNo,s.stuName,s.stuSex,s.stuAge); } } break; } } } }//Main }//class struct Student { public string stuNo; public string stuName; public char stuSex; public short stuAge; } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服