zoukankan      html  css  js  c++  java
  • 结构体集合面向对象

    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();
            }
        }
    }
  • 相关阅读:
    后缀数组 (Suffix Array) 学习笔记
    Miller-Rabin 素性测试 与 Pollard Rho 大整数分解
    [ USACO 2013 OPEN ] Photo
    清华集训2016做题记录
    「UNR#2」黎明前的巧克力
    「UNR#1」奇怪的线段树
    Atcoder Grand Contest 018 E
    「NOI2015」小园丁与老司机
    「集训队作业2018」三角形
    Codeforces 878 E. Numbers on the blackboard
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4520936.html
Copyright © 2011-2022 走看看