namespace wwz
{
    class Program
    {
        struct student
        {
            public string name;
            public int chengji;
            public int cno;
        
        }
        public ArrayList paixu(ArrayList a)   //排序函数
        {
            int n = a.Count;
            for (int i = 1; i <= a.Count; i++)
            {
                for (int j = 1; j <= a.Count - i; j++)
                {
                 
                    if (((student)a[j - 1]).chengji < ((student)a[j]).chengji)
                    {   student temp ;
                        temp = (student)a[j - 1];
                        a[j - 1] = (student)a[j];
                        a[j] = temp;
                    }
                }
            }
            return a;
        }
        static void Main(string[] args)
        {
            ArrayList al = new ArrayList();
            student a = new student();
            Console.WriteLine("请输入人数");
            int b = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= b; i++)
            {
                Console.WriteLine("请输入您的名字");
                a.name = Console.ReadLine();
                Console.WriteLine("请输入您的成绩");
                a.chengji = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入您的学号");
                a.cno = Convert.ToInt32(Console.ReadLine());
                al.Add(a);
            }

             new Program().paixu(al);//调用函数进行排序
        

            for (int i = 0; i < al.Count; i++)
            {
                Console.WriteLine("名字为" + ((student)al[i]).name + "成绩为" + ((student)al[i]).chengji + "学号为" + ((student)al[i] ).cno);
            }
            double n = 0;  //定义总分
            for (int i = 0; i < b; i++)
            {
                n +=((student)al[i]).chengji; //总分=总分+每个人的成绩
            } 
            Console.WriteLine(n); //输出总分
            double avg = n / b;//定义平均分的公式
            Console.WriteLine(avg);//输出平均分
            Console.ReadLine();
        }
    }
}

 

相关文章:

  • 2020-10-08
  • 2021-06-20
  • 2021-04-05
  • 2021-12-02
  • 2021-10-12
  • 2021-07-22
  • 2021-09-29
  • 2021-10-15
猜你喜欢
  • 2022-01-03
  • 2021-09-03
  • 2021-12-09
  • 2021-08-31
  • 2022-12-23
  • 2022-02-18
  • 2021-07-29
相关资源
相似解决方案