1、namespace Alex_11_30_Practice { public struct Student//定义结构体★★关键 { //将以下字段保留在结构体中 public int number; public string Name; public float num1; public float num2; public float num3; } class Program { public sta
2、tic int count = 0;//定义下标计数器 static void Main(string[] args) { //首先打印出程序界面打印 Student[] stu = new Student[50];//实例化一个结构体50数组 bool b = true; do { Console.WriteLine("==============================
3、"); Console.WriteLine(" ☆☆★学生成绩管理系统★☆☆"); Console.WriteLine("========================================================"); Console.WriteLine("\t0.退出系统\t1录入信息\t2浏览信息"); Console.WriteLine("\t3.信息排
4、序\t4插入信息\t5删除信息"); Console.WriteLine("\t6.查找信息\t7修改信息\t8清 屏"); Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); Console.WriteLine("请选择功效:"); string str1 =Console.ReadLine(); switch (
5、str1)//用switch语句来实现功效选择 { case "0": Console.WriteLine("确定退出系统(Y/N)Alex编写"); four: string str2=Console.ReadLine(); if (str2 == "Y" || str2 == "y") {
6、 b = false; } else if (str2 == "N" || str2 == "n") { break; } else {
7、 Console.Write("请正确输入:"); goto four; } break; case "1": Insert(stu);break; case "2": B(stu); break; case "3": S(stu); break; case "4
8、": I(stu); break; case "5": Del(stu); break; case "6": L(stu); break; case "7": R(stu); break; case "8": Console.Clear(); break; default: Console.WriteLine(" 警告:请输入正确选项!"); break;
9、 } } while (b); } public static void Insert(Student[] st)//方法-录入信息 { char ch = 'y'; while (ch == 'y' || ch == 'Y') { one: Console.Write("请输入学号:");//用循环语句会很繁
10、琐,使用goto语句迎刃而解 st[count].number = Int32.Parse(Console.ReadLine()); for (int i = 0; i < count + 1; i++)//判定学号是否相同 goto语句应用 { if (st[i].number == st[count].number && (i != count)) {
11、 Console.WriteLine(" 输入学号已存在!输入信息无效!"); st[count].number = st[count - 1].number; goto one; } } ooo:
12、 Console.Write("请输入姓名:");//判定姓名不为空 st[count].Name = Console.ReadLine(); if (st[count].Name==" " ) { Console.WriteLine(" 警告:输入姓名为空!输入信息无效!"); goto ooo;
13、 } Console.Write("请输入第一门成绩:"); st[count].num1 = float.Parse(Console.ReadLine()); Console.Write("请输入第二门成绩:"); st[count].num2 = float.Parse(Console.ReadLine()); Console.Write("请输入第三门成绩:"
14、); st[count].num3 = float.Parse(Console.ReadLine()); count++; two:Console.WriteLine("是否继续Y/N");//goto语句跳转至此 string str2 = Console.ReadLine(); if (str2 == "Y" ||
15、 str2 == "y") { ch = char.Parse(str2); } else if (str2 == "N" || str2 == "n") { break; } else {
16、 Console.WriteLine("请输入正确选择符号!"); goto two;//goto语句使用 } } } public static void R(Student[] st)//方法-修改信息 { if (count == 0) { Console.Writ
17、eLine(" 警告:请先输入学生成绩信息!"); } else { Console.Write("请输入您需要修改学生信息学号:"); int num4 = Int32.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { if (num4 == st
18、[i].number) { Console.WriteLine("请输入您要修改信息:"); Console.WriteLine("\t0.退出选项\t1.修改姓名\t2.修改第一门课成绩"); Console.WriteLine("\t3.修改第二门课成绩\t\t4.修改第三门课成绩"); int num5 = Int32.Parse(Console.R
19、eadLine()); switch (num5) { case 0: break; case 1: Console.Write("姓名:"); string name2 = Console.ReadLine();
20、 st[i].Name = name2; B(st); break; case 2: Console.Write("第一门课成绩:"); float num6 = float.Parse(Console.ReadLine());
21、 st[i].num1 = num6; B(st); break; case 3: Console.Write("第二门课成绩:"); float num7 = float.Parse(Console.ReadLine());
22、 st[i].num2 = num7; B(st); break; case 4: Console.Write("第三门课成绩:"); float num8 = float.Parse(Console.ReadLin
23、e()); st[i].num3 = num8; B(st); break; } } } } } public static v
24、oid L(Student[] st)//方法-查找信息有 { Console.Write("请输入您要查找学生姓名:"); string sName = Console.ReadLine(); if (count != 0) { Console.WriteLine("学号\t姓名\t第一门课\t第二门课\t第三门课\t平均分"); for (int i = 0; i < count; i++)
25、 { if (st[i].Name == sName) { float ave = (st[i].num1 + st[i].num2 + st[i].num3) / 3; Console.WriteLine(st[i].number + "\t" + st[i].Name + "\t" + st[i].num1 + "\t" + "\t"
26、 st[i].num2 + "\t" + "\t" + st[i].num3 + "\t" + "\t" + ave); } } } else { Console.WriteLine(" 警告:请先输入学生信息!"); } }
27、 public static void B(Student[] st) //方法-浏览信息 { if (count == 0) { Console.WriteLine(" 警告:无学生信息可浏览!!"); } else { Console.WriteLine("学号\t姓名\t第一门课\t第二门课\t第三门课\t平均分");
28、 for (int i = 0; i < count; i++) { float ave = (st[i].num1 + st[i].num2 + st[i].num3) / 3; Console.WriteLine(st[i].number + "\t" + st[i].Name + "\t" + st[i].num1 + "\t" + "\t" + st[i].num2 + "\t" + "\t" + st[i].num3 + "\t" +
29、 "\t" + ave); } } } public static void I(Student[] st)//方法-插入信息 { Console.WriteLine("请输入需要插入学员信息:"); Insert(st);//直接调用录入信息方法 } public static void S(Student[] st)//方法-信息排序 { Cons
30、ole.WriteLine("\ta.按学号排序\t\tb.按成绩排序"); string str = Console.ReadLine();//按学号排序 冒泡排序法 小到大 if (str == "a"||str=="A") { for (int j = 0; j < count; j++) { for (int i = 1; i < count-j; i++)
31、{ if (st[i - 1].number > st[i].number) { Student temp = st[i]; st[i] = st[i - 1]; st[i - 1] = temp;//小->大 } }
32、 } B(st); } else if (str == "b"||str=="B")//按平均分排序 冒泡排序法 大到小 { for (int j = 0; j < count; j++) { for (int i = 1; i < count-j; i++) { f
33、loat ave1 = (st[i - 1].num1 + st[i - 1].num2 + st[i - 1].num3) / 3; float ave2 = (st[i].num1 + st[i].num2 + st[i].num3) / 3; if (ave1 < ave2) { Student temp = st[i]; s
34、t[i] = st[i - 1]; st[i - 1] = temp; } } } B(st); } else { Console.WriteLine("请正确输入!"); } }
35、 public static void Del(Student[] st)//方法-删除信息 { Console.Write("请输入您要删除学号:"); int num = Int32.Parse(Console.ReadLine());//Console.Read是读字符ASCII码值 for (int n = 0; n < count; n++) { if (num == st[n].number)
36、 { for (int i = 0; i < count; i++) { if (num == st[i].number) { for (int j = 0; j < count; j++) { if (num
37、 st[j].number) { num = j; } } for (int k = num; k < count - 1; k++)//把其后面值赋给要删除值,同时count-1 { st[k] = st[k + 1]; } count--; B(st); } } } } } } }






