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();
            }
        }
    }
  • 相关阅读:
    C++之STL一般总结
    QT学习第2天
    Linux下Awk详解(转载)
    Mac下开启FTPserver
    Mac下QT错误,Xcode配置解决办法
    C++之STL
    关于Java自动拆箱装箱中的缓存问题
    二分查找
    冒泡排序及优化
    Java中String常用方法总结
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4520936.html
Copyright © 2011-2022 走看看