码迷,mamicode.com
首页 > 其他好文 > 详细

15、结构体练习

时间:2015-02-28 22:55:47      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 具体要求:
A.从控制台循环录入任意个同学的信息跟成绩(学号,姓名,C语言分数)使用结构体技术分享    
B.在控制台打印本班的总分和平均分,并打印本班最高分、最低分的学生信息
技术分享C.按成绩高低打印本班成绩册并排出名次技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace jiegouti2
{
    class Program
    {
        struct student
        {
            public string xuehao;
            public string xingming;
            public decimal fenshu;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎使用学生分数管理系统!");
            Console.WriteLine("请输入学生人数");
            int shu = int.Parse(Console.ReadLine());
            student[] shuzu = new student[shu];
            decimal sum = 0;
            for (int m = 0; m < shu; m++)
            {
                Console.WriteLine("请输入第{0}个学生的\n学号、姓名、C语言分数", m + 1);
                string a = Console.ReadLine();
                string[] b = a.Split(new char[] { \t });
                shuzu[m].xuehao = b[0];
                shuzu[m].xingming = b[1];
                shuzu[m].fenshu = decimal.Parse(b[2]);
                sum += shuzu[m].fenshu;
            }

            for (int m = 0; m < shu-1; m++)
            {
                for (int n = m+1; n < shu; n++)
                {
                    if (shuzu[m].fenshu < shuzu[n].fenshu)
                    {
                        student zhong = new student();
                        zhong = shuzu[n];
                        shuzu[n] = shuzu[m];
                        shuzu[m] = zhong;
                    }
                }
            }

            Console.WriteLine("总分是:{0}", sum);
            Console.WriteLine("平均分是:{0}", sum / shu);
            Console.WriteLine("最高分是学号{0}姓名{1}的{2}分", shuzu[0].xuehao.ToString(), shuzu[0].xingming.ToString(), shuzu[0].fenshu.ToString());
            Console.WriteLine("最低分是学号{0}姓名{1}的{2}分", shuzu[shu - 1].xuehao.ToString(), shuzu[shu - 1].xingming.ToString(), shuzu[shu - 1].fenshu.ToString());

            Console.WriteLine("降序排列为:\n名次\t学号\t姓名\t分数");
            for (int m = 0; m < shu; m++)
            {
                Console.WriteLine((m+1)+"\t"+shuzu[m].xuehao + "\t" + shuzu[m].xingming + "\t" + shuzu[m].fenshu);
            }
            Console.ReadLine();
        }
    }
}

效果如下图所示:

技术分享

15、结构体练习

标签:

原文地址:http://www.cnblogs.com/XMH1217423419/p/4306252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!