zoukankan      html  css  js  c++  java
  • 面向对象练习1

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication40
    {
        class Program
        {
            struct student
            {
                public string xueshengname;
                public int xuehao;
                public int fenshu;
            }
            public ArrayList paixu(ArrayList al)
            {
                for (int i = 0; i < al.Count; i++)
                {
                    for (int j = i; j < al.Count - 1; j++)
                    {
                        if (((student)al[i]).fenshu < ((student)al[j + 1]).fenshu)
                        {
                            student temp = (student)al[i];
                            al[i] = al[j + 1];
                            al[j + 1] = temp;
                        }
                    }
                }
                return al;
    
            }
            static void Main(string[] args)
            {
                ArrayList al = new ArrayList();
                student a = new student();
                Console.WriteLine("请输入人数");
                int n = Convert.ToInt32(Console.ReadLine());
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine("请输入第"+(i+1)+"人的姓名");
                    a.xueshengname = Console.ReadLine();
                    Console.WriteLine("请输入第" + (i + 1) + "人的学号");
                    a.xuehao = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("请输入第" + (i + 1) + "人的成绩");
                    a.fenshu = Convert.ToInt32(Console.ReadLine());
                    al.Add(a);
                }
                new Program().paixu(al);
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine((((student)al[i]).xueshengname) + "	" + (((student)al[i]).xuehao) + "	" + (((student)al[i]).fenshu));
                }
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    Hihocoder-小Hi的烦恼
    Python包下载与离线安装
    Shell输出颜色设置
    MySQL主从配置
    MySQL初始化与用户配置
    [转]常用 GDB 命令中文速览
    搭建github静态博客
    树莓派上手
    vim安装与配置
    数组,看了你就懂了!
  • 原文地址:https://www.cnblogs.com/wwJ0312/p/4520161.html
Copyright © 2011-2022 走看看