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();
            }
        }
    }
  • 相关阅读:
    20162310 《程序设计与数据结构》课程总结
    实验五数据结构综合应用 20162310
    Dijkstra
    图的深度优先遍历与广度优先遍历以及最小生成树
    课堂练习之链表节点删除与构建堆
    算法复杂度
    构造Huffman以及实现
    索引和查找课堂笔记与解读同伴问题和收获
    课下测试ch17&ch18
    课堂作业之杨辉三角形
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4520936.html
Copyright © 2011-2022 走看看