结构体练习题

具体要求:

A.从控制台循环录入10个同学的信息跟成绩(学号,姓名,C语言分数)使用结构体

  

 B. 在控制台打印本班的总分和平均分,并打印本班最高分、最低分的学生信息

 

C. 按成绩高低打印本班成绩册并排出名次

 

 public struct Student
    {
        public int NO;
        public string Name;
        public double Cyy;
        public double sum;
    }

class Program
{

//输入函数

        static student[] ShuRu(student[] s)
        {
            Console.WriteLine("您好!欢迎使用学员计分系统!");
            Console.WriteLine("******************************");
            for (int i = 0; i < s.Length ;i++ )
            {
                Console.WriteLine("请输入第"+(i+1)+"个学生的");
                Console.WriteLine("学号"+","+"姓名"+","+"C语言分数");
                string zifu = Console.ReadLine();
                string[] atm = zifu.Split('\t');
                s[i].NO = atm[0];
                s[i].Name = atm[1];
                s[i].Score = Convert.ToInt32(atm[2]);
            }
            Console.WriteLine("*******************");
            return s;
        }
static void Shuru(Student[] s)
        {
            double sum = 0;
            for (int i = 0; i < s.Length; i++)
            {
                sum = sum + s[i].Cyy;
            }
            Console.WriteLine("本班的总分数为:" + sum);
            Console.WriteLine("本班的平均分数为:" + sum / s.Length);
            Console.WriteLine("本班的最高分为:学号是" + s[0].NO + "姓名是" + s[0].Name + "" + s[0].Cyy + "");
            Console.WriteLine("本班的最低分为:学号是" + s[3].NO + "姓名是" + s[3].Name + "" + s[3].Cyy + "");
            Console.WriteLine();
        }
        static Student[] Paixu(Student[] s)
        {
            for (int i = 1; i <= s.Length - 1; i++)
            {
                for (int j = 1; j <= s.Length - i; j++)
                {
                    if (s[j].Cyy > s[j - 1].Cyy)
                    {
                        Student temp = s[j];
                        s[j] = s[j - 1];
                        s[j - 1] = temp;
                    }
                }
            }
            // Console.WriteLine("本班的最高分为:学号是" + s[0].NO + "姓名是" + s[0].Name + "的" + s[0].Cyy + "分");
            // Console.WriteLine("本班的最低分为:学号是" + s[3].NO + "姓名是" + s[3].Name + "的" + s[3].Cyy + "分");
            return s;
        }
        static void ShuChu(Student[] s)
        {
            Console.WriteLine("名次\t学号\t姓名\t成绩");
            for (int i = 0; i < s.Length; i++)
            {
                Console.Write((i + 1) + "\t");
                Console.Write(s[i].NO + "\t");
                Console.Write(s[i].Name + "\t");
                Console.Write(s[i].Cyy + "\n");
            }
        }
        static void Main(string[] args)
        {
            //做一个结构体数组
            Student[] s = new Student[4];

            s = ShuRu(s);

            s = Paixu(s);

            Shuru(s);

            ShuChu(s);
        }
}

 

posted on 2015-05-28 15:21  qq蓝光  阅读(202)  评论(0编辑  收藏  举报

导航