题目如下:

在控制台程序中使用结构体、集合,完成下列要求
项目要求:
一、连续输入5个学生的信息,每个学生都有以下4个内容:
1、序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1,第二个是2,以此类推
2、学号 - 必填,如:S001,S002... 以此类推
3、姓名 - 必填
4、成绩 - 大于等于0,小于等于100

以上内容必须按照要求填写,请写好相应的验证,如果没填写正确,则重复填写到正确为止

二、5个学生信息都输入完毕后,按照分数从高到低的顺序将学生信息展示出来
显示格式如下:

==============学生成绩展示=================
序号    学号    姓名     成绩
  3    S003    张三     100
  1    S001    李四     99
  2    S002    王五     98

 

程序代码如下

1、class 类下的结构体:

struct Student
{
public int Id;
public string Code;
public string Name;
public decimal Score;
}

2、主函数:

ArrayList list = new ArrayList();//放置全部学生信息的集合

//循环添加5个学生信息
Console.Write("请输入学生总个数:");
int i = Convert.ToInt32(Console.ReadLine());

for (int a = 1; a <= i; a++)
{
Student s = new Student();
s.Id = a;

#region 学生编号输入
while (true)
{
Console.Write("请输入第"+a+"个学生编号:");
s.Code = Console.ReadLine();
if (s.Code == "")
{
Console.WriteLine("学生编号不能为空!");
}
else
{
break;
}
}
#endregion

#region 学生姓名输入
while (true)
{
Console.Write("请输入第" + a + "个学生姓名:");
s.Name = Console.ReadLine();
if (s.Name == "")
{
Console.WriteLine("学生姓名不能为空!");
}
else
{
break;
}
}
#endregion

#region 学生成绩输入
while (true)
{
Console.Write("请输入第" + a + "个学生成绩:");
try
{
s.Score = Convert.ToInt32(Console.ReadLine());

if (s.Score >= 0 && s.Score <= 100)
{
break;
}
else
{
Console.Write("成绩区间必须在0~100之间");
}

}
catch
{
Console.WriteLine("成绩输入有误!请输入数字!");
}
}
#endregion

list.Add(s);
Console.WriteLine("-----------------------------");
}

//排序
#region 冒泡排序
for (int a = 0; a < list.Count - 1; a++)
{
for (int b = a + 1; b < list.Count; b++)
{
Student s1 = (Student)list[a];
Student s2 = (Student)list[b];

if (s1.Score < s2.Score)
{
Student zhong = (Student)list[a];
list[a] = list[b];
list[b] = zhong;
}
}
}
#endregion


//打印显示

Console.WriteLine("========学生信息展示=========");
Console.WriteLine("序号 学号 姓名 成绩");

for (int a = 0; a < list.Count; a++)
{
Student sss = (Student)list[a];
Console.WriteLine(sss.Id+" "+sss.Code+" "+sss.Name+" "+sss.Score);
}

Console.ReadKey();

3、执行后显示结果: