C#学员管理系统

C#学员管理系统是在控制台输出的项目,和OOP学员管理系统相似。

① 创建一个学员的实体类Student,实现其构造方法和封装:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// 实体类
/// </summary>
namespace BaseXm
{/// <summary>/// 学员的实体类/// </summary>public class Student{/// <summary>/// 学号/// </summary>private int _id;/// <summary>/// 姓名/// </summary>private string _name;/// <summary>/// 年龄/// </summary>private int _age;/// <summary>/// 性别/// </summary>private string _sex;/// <summary>/// 分数/// </summary>private int _grade;public override string ToString(){StringBuilder sb = new StringBuilder();sb.Append("学号:");sb.Append(_id);sb.Append(",姓名:");sb.Append(_name);sb.Append(",年龄:");sb.Append(_age);sb.Append(",性别:");sb.Append(_sex);sb.Append(",分数");sb.Append(_grade);return sb.ToString();}public int Id{get{return _id;}set{_id = value;}}public string Name{get{return _name;}set{_name = value;}}public int Age{get{return _age;}set{_age = value;}}public string Sex{get{return _sex;}set{_sex = value;}}public int Grade{get{return _grade;}set{_grade = value;}}public Student(int _id, string _name, int _age, string _sex, int _grade){this.Id = _id;this.Name = _name;this.Age = _age;this.Sex = _sex;this.Grade = _grade;}public Student(){}}
}

② 写一个老师管理学员的接口ITeacher,写增删查改的方法:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace BaseXM
{/// <summary>/// 管理的接口类  泛型/// </summary>public interface ITeacher<T> where T : class{/// <summary>/// 增加学员/// </summary>/// <param name="t">学员对象</param>void AddStudent(T t);/// <summary>/// 编辑修改学员/// </summary>/// <param name="t">学号</param>void EditStudent(T t);/// <summary>/// 删除学员/// </summary>/// <param name="i">学号</param>void DeleteStudent(int i);/// <summary>/// 查询单个学员根据id/// </summary>/// <param name="i"></param>T SelectStudentById(int i);/// <summary>/// 查询最高分或最低分学员/// </summary>/// <param name="i"></param>ArrayList SelectMaxOrMin(int i);/// <summary>/// 查询总分与平均分/// </summary>int[] SelectSumAndAvg();/// <summary>/// 查询全部学员根据年龄或分数或学号排序/// </summary>ArrayList SelectStudentAgeGradeId(string str);}
}

③写学员管理的接口类 IStudent,实现老师的接口以及学员的实体类ITeacher:

using BaseXM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace BaseXm
{/// <summary>/// 学员管理的接口类/// </summary>public interface IStudent : ITeacher<Student>{}
}

④实现学生管理的实现类,StudentManage,接着实现接口IStudent:

using BaseXm;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
/// <summary>
/// 实现类
/// </summary>
namespace BaseXM
{/// <summary>/// 学生管理实现类/// </summary>public class StudentManage : IStudent{#region 正则表达式 /// <summary>/// 正则表达式/// </summary>Regex reg = new Regex("^[0-9]+$");#endregion#region 学员集合List/// <summary>/// 学员集合 List/// </summary>private static ArrayList ls = new ArrayList();#endregion#region 登录信息  增加学员集合数据AddStudents()/// <summary>/// 增加学员数据/// </summary>public static void AddStudents(){//赋值ls.Add(new Student(1, "拾亿", 18, "男", 136));           }#endregion#region 增加学员AddStudent(Student q)/// <summary>/// 增加学员/// </summary>/// <param name="q"></param>public void AddStudent(Student q){int i = 1;foreach (Student s in ls){if (s.Id >= i)i = s.Id + 1;}q.Id = i;ls.Add(q);}#endregion#region 删除学员DeleteStudent(int i)/// <summary>/// 删除学员/// </summary>/// <param name="i">学号</param>public void DeleteStudent(int i){int p = 0;foreach (Student s in ls){if (s.Id == i){ls.Remove(s);break;}p++;}}#endregion#region 修改学员EditStudent(Student r)/// <summary>/// 修改学员/// </summary>/// <param name="r">学员对象</param>public void EditStudent(Student r){foreach (Student s in ls){if (s.Id == r.Id){s.Name = r.Name;s.Age = r.Age;s.Sex = r.Sex;s.Grade = r.Grade;break;}}}#endregion#region 登录界面 Login()public void Login(){while (true){//Console.ForegroundColor = ConsoleColor.Blue; //设置字体颜色为蓝色Console.WriteLine("《《《《《《--------------------------------------------------------------&&&&----欢迎您来到 学员 管理系统----&&&&-------------------------------------------------------------》》》》》》》");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");Console.WriteLine("---------------------------------------------------------------------------    此系统需要先登录后方可使用哦    ------------------------------------------------------------------------------");Console.WriteLine("                                                                            ----    请输入   学号    ----                                                                              ");string sy = Console.ReadLine().Trim();Console.WriteLine("                                                                            ----    请输入   姓名    ----                                                                              ");string wl = Console.ReadLine().Trim();if (sy.Equals("1") && wl.Equals("拾忆")){ShowMain();}else{Console.WriteLine("学号或者姓名没有输入或者有误");Login();}break;}}#endregion#region 一级菜单   界面/// <summary>/// 一级菜单 主界面/// </summary>/// public void ShowMain(){while (true){Console.ForegroundColor = ConsoleColor.Blue; //设置字体颜色为蓝色Console.WriteLine();Console.WriteLine("《《《《《《--------------------------------------------------------------&&&&----欢迎您来到 学员 管理系统----&&&&-------------------------------------------------------------》》》》》》》");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");Console.WriteLine("---------------------------------------------------------------------------------    本系统有如下操作    ------------------------------------------------------------------------------------");Console.WriteLine("                                                                                   ----1.教员界面----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                   ----2.学员界面----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                 ----3.退出学员管理系统----                                                                                  ");Console.WriteLine();Console.WriteLine("                                                                            ----《《《《请输入1--2的数字》》》》----                                                                      ");Console.WriteLine();Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string w = Console.ReadLine().Trim();if (w.Equals("1")){ShowMain11();}else if (w.Equals("2")){ShowMain12();}else if (w.Equals("3")){Console.WriteLine("         退出成功!!!欢迎您再次使用哦         ");}else{Console.WriteLine("         输入错误!!!请依据提示重新请输入1--3的数字哦         ");continue;}break;}}/// <summary>/// 一级菜单第一个 教员查看信息/// </summary>public void ShowMain11(){while (true){Console.WriteLine("                                                                                   ----1.查看学员信息----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                   ----2.增加学员信息----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                   ----3.修改学员信息----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                   ----4.删除学员信息----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                   ----5.返回上级菜单----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                 ----6.退出学员管理系统----                                                                                  ");Console.WriteLine();Console.WriteLine("                                                                            ----《《《《请输入1--5的数字》》》》----                                                                      ");Console.WriteLine();Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string x = Console.ReadLine().Trim();if (x.Equals("1")){ShowMain123();}else if (x.Equals("2")){ShowMain212();}else if (x.Equals("3")){ShowMain23();}else if (x.Equals("4")){ShowMain24();}else if (x.Equals("5")){ShowMain();break;}else if (x.Equals("6")){Console.WriteLine("         退出成功!!!欢迎您再次使用哦         ");}else{Console.WriteLine("         输入错误!!!请依据提示重新请输入1--5的数字哦         ");continue;}break;}}///  <summary>/// 一级菜单第二个 学员查看信息/// </summary>public void ShowMain12(){while (true){Console.WriteLine("                                                                                   ----1.查看学员信息----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                                 ----2.退出学员管理系统----                                                                                  ");Console.WriteLine();Console.WriteLine("                                                                                   ----3.返回上级菜单----                                                                                    ");Console.WriteLine();Console.WriteLine("                                                                            ----《《《《请输入1--2的数字》》》》----                                                                      ");Console.WriteLine();Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string x = Console.ReadLine().Trim();if (x.Equals("1")){ShowMain124();}else if (x.Equals("2")){Console.WriteLine("         退出成功!!!欢迎您再次使用哦         ");break;}else if (x.Equals("3")){ShowMain();}else{Console.WriteLine("         输入错误!!!请依据提示重新请输入1--2的数字哦         ");}break;}}#endregion#region 二级菜单第一个  查看信息/// <summary>  /// 二级菜单第一个  教员查看学员信息/// </summary>/// private void ShowMain123(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.查看单个学员信息         ");Console.WriteLine("         2.查看所有学员信息         ");Console.WriteLine("         3.返回上级菜单         ");Console.WriteLine("         请输入1--3的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){ShowMain31();break;}else if (s.Equals("2")){ShowMain32();break;}else if (s.Equals("3")){ShowMain11();break;}else{Console.WriteLine("         输入错误!!!请按提示重新请输入1--3的数字!!!         ");}}}/// <summary>/// 二级菜单第二个 学员查看信息/// </summary>private void ShowMain124(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.查看单个学员信息         ");Console.WriteLine("         2.查看所有学员信息         ");Console.WriteLine("         3.返回上级菜单         ");Console.WriteLine("         请输入1--3的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){ShowMain311();break;}else if (s.Equals("2")){ShowMain322();break;}else if (s.Equals("3")){ShowMain12();break;}else{Console.WriteLine("         输入错误!!!请按提示重新请输入1--3的数字 !!!         ");}}}#endregion#region 二级菜单第二个   增加学员信息/// <summary>/// 二级菜单第二个/// </summary>private void ShowMain212(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.增加学员信息         ");Console.WriteLine("         2.返回上级菜单         ");Console.WriteLine("         请输入1--2的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){while (true){Console.WriteLine("         请输入您要增加的学员的姓名:         ");string name = Console.ReadLine().Trim();if (name.Length < 2 || name.Length > 20){Console.WriteLine("         姓名只能在2位到20位之间         ");Console.WriteLine("         请输入a或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("a"))continue;}else{while (true){Console.WriteLine("         请输入您要增加的学员的年龄         ");string s2 = Console.ReadLine().Trim();if (!reg.Match(s2).Success){Console.WriteLine("         输入的不是数字         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Equals("1"))continue;}else{int age = int.Parse(s2);if (age < 10 || age > 50){Console.WriteLine("         年龄只能在10-50岁之间的整数      ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Equals("1"))continue;}else{while (true){Console.WriteLine("         请输入你要增加的学员的性别:         ");string sex = Console.ReadLine();if (!(sex.Equals("男") || sex.Equals("女"))){Console.WriteLine("         性别只能为男或者女哦         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}else{while (true){Console.WriteLine("         请输入您要增加的学员的分数(0~150):         ");string s3 = Console.ReadLine().Trim();Match ms2 = reg.Match(s3);if (!ms2.Success){Console.WriteLine("         输入的不是数字(0~150之间)          ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}else{int grade = int.Parse(s3);if (grade > -1 && grade < 151){Console.WriteLine("姓名:" + name + ",年龄:" + age + ",性别:" + sex + ",分数:" + grade);Console.WriteLine("         您确认增加这位学员吗?请输入:1(确认)其它字符(取消)         ");if (!Console.ReadLine().Trim().Equals("1")){Console.WriteLine("         取消成功         ");break;}AddStudent(new Student(0, name, age, sex, grade));Console.WriteLine("         增加成功  !!!!       ");break;}else{Console.WriteLine("         学员的分数在0-150分之间         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}}break;}}break;}}}break;}}break;}}else if (s.Equals("2")){ShowMain11();return;}else{Console.WriteLine("          请输入1--2的数字!!!         ");}}}#endregion#region 二级菜单第三个   修改学员信息void ShowMain23(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.输入要修改的学号         ");Console.WriteLine("         2.返回上级菜单         ");Console.WriteLine("         请输入1--2的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){while (true){while (true){Console.WriteLine("         请输入您要修改的学员的学号(阿拉伯数字):         ");string t = Console.ReadLine().Trim();if (!reg.Match(t).Success){Console.WriteLine("        请输入1--2的数字         ");break;}else{int id = int.Parse(t);Student x = SelectStudentById(id);if (x == null){Console.WriteLine("         教员没有添加此学号哦         ");break;}Console.WriteLine("         原来的姓名:" + x.Name + "          ");Console.WriteLine("         请输入您要修改后的学员的姓名:         ");string name = Console.ReadLine().Trim();if (name.Length < 2 || name.Length > 20){Console.WriteLine("         姓名需要在2位到20位之间!!!         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}else{while (true){Console.WriteLine("         原来年龄:" + x.Age + "          ");Console.WriteLine("         请输入您要修改后的学员的年龄         ");string s2 = Console.ReadLine().Trim();if (!reg.Match(s2).Success){Console.WriteLine("         学员的年龄只能为10-50之间的数字         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Equals("1"))continue;}else{int age = int.Parse(s2);if (age < 10 || age > 50){Console.WriteLine("         学员的年龄在10-50岁之间!!!         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Equals("1"))continue;}else{while (true){Console.WriteLine("         原姓别:" + x.Sex + "          ");Console.WriteLine("         请输入修改后的学员的性别:         ");string sex = Console.ReadLine();if (!(sex.Equals("男") || sex.Equals("女"))){Console.WriteLine("         学员的性别只能位男或者女哦         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}else{while (true){Console.WriteLine("         原分数:" + x.Grade + "          ");Console.WriteLine("         请输入修改后的学员的分数(0~150):         ");string s3 = Console.ReadLine().Trim();Match ms2 = reg.Match(s3);if (!ms2.Success){Console.WriteLine("         学员的分数只能在0-150分之间的整数         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}else{int grade = int.Parse(s3);if (grade > -1 && grade < 151){Console.WriteLine("         原信息:" + x + "          ");Student y = new Student(x.Id, name, age, sex, grade);Console.WriteLine("         修改后的信息:" + y + "          ");Console.WriteLine("         您确认修改这位学员吗?请输入:1(确认)0(取消)         ");if (!Console.ReadLine().Trim().Equals("1")){Console.WriteLine("         取消成功!         ");break;}EditStudent(y); Console.WriteLine("         修改成功  !!!         ");break;}else{Console.WriteLine("          学员的分数只能在0-150分之间的整数!!!         ");Console.WriteLine("         请输入1或其他任意字符退出         ");if (Console.ReadLine().Trim().Equals("1"))continue;}}break;}}break;}}}break;}}}break;}break;}}else if (s.Equals("2")){ShowMain11();return;}else{Console.WriteLine("          请输入1--2的数字哦 !!!         ");}}}#endregion#region 二级菜单第四个   删除学员信息void ShowMain24(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.输入要删除的学号         ");Console.WriteLine("         2.返回上级菜单         ");Console.WriteLine("         请输入1--2的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){while (true){Console.WriteLine("         请输入你要删除的学员的学号(阿拉伯数字):         ");string a = Console.ReadLine().Trim();if (!reg.Match(a).Success){Console.WriteLine("         请您输入学号数字哦!!!         ");break;}else{int id = int.Parse(a);Student student = SelectStudentById(id);if (student == null){Console.WriteLine("         教员没有添加此学号哦,学号为阿拉伯数字          ");}else{Console.WriteLine(student);Console.WriteLine("         您确定要删除此位学员吗?请输入:1(确认) 其他(取消)         ");if (Console.ReadLine().Trim().Equals("1")){DeleteStudent(id);Console.WriteLine("         删除成功! !!        ");}else{Console.WriteLine("         取消成功! !!        ");}}}break;}}else if (s.Equals("2")){ShowMain11();break;}else{Console.WriteLine("         输入错误!!!请输入1--2的数字哦        ");}}}#endregion#region 三级菜单第一个    查看单个学员信息/// <summary>/// 三级菜单第一个 教员查看/// </summary>private void ShowMain31(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.根据学号查看信息         ");Console.WriteLine("         2.查看最高分学员         ");Console.WriteLine("         3.查看最低分学员         ");Console.WriteLine("         4.返回上级菜单         ");Console.WriteLine("         请输入1--4的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");String s = Console.ReadLine().Trim();if (s.Equals("1")){Console.WriteLine("         请输入您要查找的学生的学号:         ");string s2 = Console.ReadLine().Trim();if (s2.Length > 0){Match ma = reg.Match(s2);if (ma.Success){Student s3 = SelectStudentById(int.Parse(s2));if (s3 == null){Console.WriteLine("         教员没有添加此学号哦         ");}else{Console.WriteLine(s3);}}else{Console.WriteLine("         您输入的不是数字!!!请重新选择         ");}}else{Console.WriteLine("         您输入的不是数字!!!请重新选择         ");}}else if (s.Equals("2")){ArrayList al = SelectMaxOrMin(2);if (al.Count == 0){Console.WriteLine("         此系统教员没有添加此学生哦         ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("3")){ArrayList al = SelectMaxOrMin(1);if (al.Count == 0){Console.WriteLine("         您输入的学号不存在!教员没有添加此学生哦           ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("4")){ShowMain123();break;}else{Console.WriteLine("         输入错误!请输入1--4的数字 !!!         ");}}}/// <summary>/// 三级菜单第一1个 学员查看/// </summary>private void ShowMain311(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.根据学号查看信息         ");Console.WriteLine("         2.查看最高分学员         ");Console.WriteLine("         3.查看最低分学员         ");Console.WriteLine("         4.返回上级菜单         ");Console.WriteLine("         请输入1--4的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");String s = Console.ReadLine().Trim();if (s.Equals("1")){Console.WriteLine("         请输入您要查找的学生的学号:         ");string s2 = Console.ReadLine().Trim();if (s2.Length > 0){Match ma = reg.Match(s2);if (ma.Success){Student s3 = SelectStudentById(int.Parse(s2));if (s3 == null){Console.WriteLine("         您输入的学号不存在!教员没有添加此学生哦         ");}else{Console.WriteLine(s3);}}else{Console.WriteLine("         您输入的不是数字!!!请重新选择         ");}}else{Console.WriteLine("         您输入的不是数字!!!请重新选择         ");}}else if (s.Equals("2")){ArrayList al = SelectMaxOrMin(2);if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦         ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("3")){ArrayList al = SelectMaxOrMin(1);if (al.Count == 0){Console.WriteLine("        教员没有添加此学生哦          ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("4")){ShowMain124();break;}else{Console.WriteLine("         输入错误!请输入1--4的数字 !!!         ");}}}#endregion#region 查询单个学员根据学号SelectStudentById(int i)/// <summary>/// 查询单个学员根据学号/// </summary>/// <param name="i">学号</param>public Student SelectStudentById(int i){foreach (Student s in ls){if (s.Id == i){return s;}}return null;}#endregion#region 查询单个学员最高分或最低分学员SelectMaxOrMin(int i)/// <summary>/// 查询最高分或最低分学员/// </summary>/// <param name="i">1代表最低分,2代表最高分</param>public ArrayList SelectMaxOrMin(int i){ArrayList ls2 = new ArrayList();int y = i == 1 ? 1000 : -1;if (i == 1){foreach (Student s in ls){if (s.Grade < y){y = s.Grade;}}}else{foreach (Student s in ls){if (s.Grade > y){y = s.Grade;}}}foreach (Student s in ls){if (s.Grade == y){ls2.Add(s);}}return ls2;}#endregion#region 三级菜单第二个    查看所有学员信息/// <summary>/// 三级菜单第二个 教员查看/// </summary>private void ShowMain32(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.根据年龄排序         ");Console.WriteLine("         2.根据分数排序         ");Console.WriteLine("         3.根据学号排序         ");Console.WriteLine("         4.查看总分与平均分         ");Console.WriteLine("         5.返回上级菜单         ");Console.WriteLine("         请输入1--5的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){ArrayList al = SelectStudentAgeGradeId("age");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦         ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("2")){ArrayList al = SelectStudentAgeGradeId("grade");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦         ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("3")){ArrayList al = SelectStudentAgeGradeId("id");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦         ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("4")){ArrayList al = SelectStudentAgeGradeId("id");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦         ");}else{int[] i = SelectSumAndAvg();Console.WriteLine("总分:" + i[0] + ",平均分:" + i[1]);}}else if (s.Equals("5")){ShowMain123();break;}else{Console.WriteLine("         输入错误!请输入1--5的数字         ");}}}/// <summary>/// 三级菜单第二1个 教员查看/// </summary>private void ShowMain322(){while (true){Console.WriteLine("%----------------------------%");Console.WriteLine("         1.根据年龄排序         ");Console.WriteLine("         2.根据分数排序         ");Console.WriteLine("         3.根据学号排序         ");Console.WriteLine("         4.查看总分与平均分         ");Console.WriteLine("         5.返回上级菜单         ");Console.WriteLine("         请输入1--5的数字         ");Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");string s = Console.ReadLine().Trim();if (s.Equals("1")){ArrayList al = SelectStudentAgeGradeId("age");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦          ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("2")){ArrayList al = SelectStudentAgeGradeId("grade");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦          ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("3")){ArrayList al = SelectStudentAgeGradeId("id");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦          ");}else{foreach (Student student in al){Console.WriteLine(student);}}}else if (s.Equals("4")){ArrayList al = SelectStudentAgeGradeId("id");if (al.Count == 0){Console.WriteLine("         教员没有添加此学生哦          ");}else{int[] i = SelectSumAndAvg();Console.WriteLine("总分:" + i[0] + ",平均分:" + i[1]);}}else if (s.Equals("5")){ShowMain124();break;}else{Console.WriteLine("        输入错误!请输入1--5的数字         ");}}}#endregion#region 查询所有学员并根据年龄或分数或学号排序 SelectStudentAgeGradeId(string str)/// <summary>/// 查询所有学员并根据年龄或分数或学号排序/// </summary>public ArrayList SelectStudentAgeGradeId(string str){//年龄排序if (str.Equals("age")){for (int i = 0; i < ls.Count - 1; i++){for (int y = i + 1; y < ls.Count; y++){Student s = (Student)ls[i];Student s2 = (Student)ls[y];if (s.Age < s2.Age){Student s3 = s;ls[i] = s2;ls[y] = s3;}}}}//分数排序else if (str.Equals("grade")){for (int i = 0; i < ls.Count - 1; i++){for (int y = i + 1; y < ls.Count; y++){Student s = (Student)ls[i];Student s2 = (Student)ls[y];if (s.Grade < s2.Grade){Student s3 = s;ls[i] = s2;ls[y] = s3;}}}}else{//学号排序for (int i = 0; i < ls.Count - 1; i++){for (int y = i + 1; y < ls.Count; y++){Student s = (Student)ls[i];Student s2 = (Student)ls[y];if (s.Id > s2.Id){Student s3 = s;ls[i] = s2;ls[y] = s3;}}}}return ls;}#endregion#region 查询总分和平均分SelectSumAndAvg()/// <summary>/// 查询总分和平均分,先返回总分再返回平均分/// </summary>public int[] SelectSumAndAvg(){int[] x = new int[2];int sum = 0;foreach (Student s in ls){sum += s.Grade;}x[0] = sum;x[1] = sum / ls.Count;return x;}#endregion}
}

⑤测试类Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace BaseXM
{class Program{static void Main(string[] args){StudentManage.AddStudents();StudentManage sm = new StudentManage();sm.Login();Console.ReadKey();}}
}

C#学员管理系统(源代码)相关推荐

  1. java计算机毕业设计企业销售管理系统源代码+数据库+系统+lw文档

    java计算机毕业设计企业销售管理系统源代码+数据库+系统+lw文档 java计算机毕业设计企业销售管理系统源代码+数据库+系统+lw文档 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 ...

  2. java学生信息管理系统排序_JAVA学生管理系统源代码(最新整理)

    <JAVA学生管理系统源代码(最新整理)>由会员分享,可在线阅读,更多相关<JAVA学生管理系统源代码(最新整理)(10页珍藏版)>请在人人文库网上搜索. 1.JAVA 学生管 ...

  3. c语言编程学生管理系统的代码,C语言学生管理系统源代码.doc

    C语言学生成绩管理系统源代码,保证能用-- #include "malloc.h" #include "stdio.h" #include "stdl ...

  4. python⾯向对象学员管理系统

    1. 系统需求 使⽤⾯向对象编程思想完成学员管理系统的开发,具体如下: 系统要求:学员数据存储在⽂件中 系统功能:添加学员.删除学员.修改学员信息.查询学员信息.显示所有学员信息.保存学员信息及退出系 ...

  5. ORM版学员管理系统

    ORM版学员管理系统 班级表 表结构 class Class(models.Model):id = models.AutoField(primary_key=True) # 主键cname = mod ...

  6. 运动会管理系统php,运动会管理系统源代码.doc

    运动会管理系统源代码 运动会管理系统源代码include#include#includestruct student /* 定义链表 */{long num;char name[10];char da ...

  7. mysql数据库小系统_Mysql数据库基础小实例 学员管理系统菜单

    package test; import java.sql.*; import java.util.Scanner; public class testSql002_StudentTest { /** ...

  8. 语言 班费管理系统源代码_固定资产管理系统开源的各种语言翻译

    固定资产管理系统开源指的是将固定资产管理系统源代码进行开发,进而得到可以免费使用的固定资产管理系统,即是开源的固定资产管理系统.固定资产管理系统简单来说就是利用现代信息技术智能化管理企业资产的管理系统 ...

  9. c语言大作业教室预约管理系统,C语言程序设计——教室管理系统(源代码))

    C语言程序设计--教室管理系统(源代码) 非常有用的. #include #include #include #define szSTR 64 #define fileDB "c:\\con ...

  10. java编写学籍管理系统_java学籍管理系统源代码.doc

    java学籍管理系统源代码 package zuoye; //主类 import java.awt.*; import java.awt.event.*; import javax.swing.*; ...

最新文章

  1. Java获取当前类名的两种方法
  2. Linux下文件的三个时间:ctime、mtime、atime的区别
  3. 从零开始入门 K8s | etcd 性能优化实践
  4. .NET Core 已经实现了PHP JIT,现在PHP是.NET上的一门开发语言
  5. Cookie、Session 和 Token区别
  6. linux如何查询一个文件夹大小,Linux下如何查看某个文件夹所占空间大小
  7. 25个学习要点帮助你从java菜鸟成为Java高手
  8. Linux经常使用到的操作
  9. css中background-position:的属性值为百分比时的用法
  10. ASP.NET 实现文件下载
  11. Java程序员的工资标准是多少
  12. 虚拟机中ip地址总是自动变化解决办法
  13. 无线通信蜂窝网络 的 覆盖范围
  14. 【IOI2000】 邮局
  15. 申请加拿大计算机研究生如何写未来计划,加拿大学习计划书模板 (study plan)
  16. 面试问到DCL失效不知所措
  17. java mysql 生僻字 乱码_mysql 生僻字乱码
  18. 工作流结合动态表单的工作流程
  19. 网页抠图(正则表达式)
  20. 微信小程序将时间戳转为日期格式

热门文章

  1. Unity3D手游开发实践《腾讯桌球》客户端开发经验总结
  2. java offset什么意思_java – “offset或count可能接近-1 1”这是什么意思
  3. 在绝望中寻找希望-中篇 写给年轻人
  4. html5淘宝注册界面设计,电商登陆注册页设计分析
  5. 三菱FX3U——红绿灯
  6. 凸集(Convex sets)
  7. 论文翻译:2022_Time-Frequency Attention for Monaural Speech Enhancement
  8. maven 为html赋版本号,maven-replacer-plugin 静态资源版本号解决方案(css/js等)
  9. 做服务器销售两个月还没开单,1月15日的销售欠款,2月20日做的收款单,为什么没有...
  10. NYOJ54-小明的存钱计划