class Student
{
public uint sNo;
public string sName;
public double sScore;
public uint No { get { return sNo; } set { sNo = value; } }
public string Name { get { return sName; } set { sName = value; } }
public double Score { get { return sScore; } set { sScore = value; } }
public void Input()
{
inName:
Console.Write("输入姓名:");
string n = Console.ReadLine();
if (n.Length < 2)
{
Console.WriteLine("姓名过短!");goto inName;
}
inNo:
Console.Write("输入学号:");
string no = Console.ReadLine();
if (no.Length != 7)
{
Console.WriteLine("请输入7位学号!");
goto inNo;
}
uint ino;
if(uint.TryParse(no,out ino) == false)
{
Console.WriteLine("请输入7位纯数字学号!");
goto inNo;
}
inScore:
Console.Write("输入分数:");
double score;
if(double.TryParse(Console.ReadLine(),out score)==false)
{
Console.WriteLine("分数输入错误!");goto inScore;
}
Name = n;No = ino;Score = score;
}
}
static Student[] Sort(Student[] ss)
{
for(int i = 0; i < ss.Length - 1; i++)
{
for(int j = i + 1; j < ss.Length; j++)
{
if (ss[i].No > ss[j].No)
{
var t = ss[i];ss[i] = ss[j];ss[j] = t;
}
}
}
return ss;
}
static List<Student> Find(Student[] ss,double v)
{
List<Student> list = new List<Student>();
foreach(var s in ss)
{
if (Math.Abs(s.Score - v) < 0.01)
{
list.Add(s);
}
}
return list;
}
static void Stat(Student[] ss)
{
Student max = ss[0];
int c = 0;
foreach(var s in ss)
{
if (s.Score < 60) c++;
if (s.Score > max.Score) max = s;
}
Console.WriteLine("最高分:{0} 不及格人数:{1}",max.Score,c);
}
static void Main(string[] args)
{
Student[] students = new Student[30];
for(int i = 0; i < 30; i++)
{
Student student = new Student();
Console.WriteLine("输入第{0}个学生信息", i + 1);
student.Input();
students[i] = student;
}
students = Sort(students);
Stat(students);
double v; Console.WriteLine("\n输入查找分数:");
Start:
if(double.TryParse(Console.ReadLine(),out v) == false)
{
Console.WriteLine("输入错误");goto Start;
}
List< Student> ss = Find(students, v);
Console.WriteLine("找到{0}条记录\n学号\t姓名\t总分",ss.Count);
foreach(var s in ss)
{
Console.WriteLine("{0}\t{1}\t{2}",s.No, s.Name, s.Score);
}
goto Start;
}
温馨提示:答案为网友推荐,仅供参考