zoukankan      html  css  js  c++  java
  • C#复习,输入学生信息排列成绩

    C#复习:
    在控制台程序中使用结构体、集合,完成下列要求
    项目要求:
    一、连续输入5个学生的信息,每个学生都有以下4个内容:
    1、序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1,第二个是2,以此类推
    2、学号 - 必填,如:S001,S002... 以此类推
    3、姓名 - 必填
    4、成绩 - 大于等于0,小于等于100

    以上内容必须按照要求填写,请写好相应的验证,如果没填写正确,则让用户重复填写到正确为止

    二、5个学生信息都输入完毕后,按照分数从高到低的顺序将学生信息展示出来
    显示格式如下:

    ==============学生成绩展示=================
    序号 学号 姓名 成绩
    3 S003 张三 100
    1 S001 李四 99
    2 S002 王五 98
    ...
    ...

    -------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            struct swe
            {
                public int xuhao;
                public string xuehao;
                public string xingming;
                public double chengji;
            }
            static void Main(string[] args)
            {
                ArrayList al = new ArrayList();
                Console.WriteLine("请输入班级人数:");
                int n = int.Parse(Console.ReadLine());
                for (int i = 1; i <= n; i++)
                {
                    swe s = new swe();
                    s.xuhao = i;
                    while (true)
                    {
                        Console.WriteLine("请输入第{0}个学生的学号:", i);
                        s.xuehao = Console.ReadLine();
                        if (s.xuehao == "")
                        {
                            Console.WriteLine("学号不能为空!");
                        }
                        else
                        {
                            break;
                        }
                    }
                    while (true)
                    {
                        Console.WriteLine("请输入第{0}个学生的姓名:", i);
                        s.xingming = Console.ReadLine();
                        if (s.xingming == "")
                        {
                            Console.WriteLine("姓名不能为空!");
                        }
                        else
                        {
                            break;
                        }
                    }
                    while (true)
                    {
                        Console.WriteLine("请输入第{0}个学生的成绩;", i);
                        try
                        {
                            s.chengji = int.Parse(Console.ReadLine());
                            if (s.chengji >= 0 && s.chengji <= 100)
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("成绩必须在0~100之间!");
                            }
                        }
                        catch
                        {
                            Console.WriteLine("成绩输入有误!");
                        }
                    }
                    al.Add(s);
                    Console.WriteLine();
                    for (int e = 0; e < al.Count - 1; e++)
                    {
                        for (int j = e + 1; j < al.Count; j++)
                        {
                            swe s1 = (swe)al[e];
                            swe s2 = (swe)al[j];
                            if (s1.chengji < s2.chengji)
                            {
                                swe zhong = (swe)al[e];
                                al[e] = al[j];
                                al[j] = zhong;
                            }
                        }
                    }
                }
                Console.WriteLine("序号 学号 姓名 成绩 ");
                foreach (object qq in al)
                {
                    Console.WriteLine(((swe)qq).xuhao + "      " +
                    ((swe)qq).xuehao + "    " +
                    ((swe)qq).xingming + "    " +
                    ((swe)qq).chengji);
                }
  • 相关阅读:
    Pytorch-情感分类实战(基于LSTM,调用torchtext)
    Pytorch-LSTM
    Pytorch-时间序列预测
    Pytorch-RNN
    SQLServer -------- 包含(charindex)
    .NET ------ 树形菜单,点击单选按钮触发相应事件
    电子秤Xk3190-A12+E 称重方式的设置方法
    串口调试工具与com口编程
    .NET ------ Repeater 遍历数据显示在页面上
    .NET ------ 将弹窗内增加选项卡
  • 原文地址:https://www.cnblogs.com/1030351096zzz/p/6099880.html
Copyright © 2011-2022 走看看