C#编写一个学生类Student,假设某班级有学生30名,请编写如下方法实现对班级学生管理

编写一个学生类Student,包含三个字段:学号(sNo),姓名(sName),总成绩(sScore)。假设某班级有学生30名,请编写如下方法实现对班级学生管理:
(1)方法input,实现学生信息录入,要求通过属性来实现类字段的数据存取;
(2)方法sort,实现按学号对学生排名;
(3)方法find,实现对学生成绩查找,即根据成绩查找学生信息;
(4)方法stat,实现学生成绩统计:打印最高分,并统计不及格学生的人数(小于60分视为不及格)。

 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;
           

        }

温馨提示:答案为网友推荐,仅供参考
相似回答