0803结构体,枚举类型

  //    struct Fenshu
    //    {
    //        public ArrayList al;
    //    }

    //    //结构体
    //    struct Student
    //    {
    //        public int no;
    //        public string name;
    //        public string sex;
    //        public Score fen;
    //    }
        //结构体内部可以直接放置另一个结构体的数据类型
        //struct Score
        //{
        //    public double yu;
        //    public double shu;
        //    public double ying;
        //}


        //enum student:int
        //{
        //    one=2,
        //    two=1,
        //    three,
        //    four=three
        //}

        //enum Weekday
        //{
        //    Sunday,
        //    Monday,
        //    Tuesday,
        //    Wendsday,
        //    Thursday,
        //    Friday,
        //    Saturday
        //}

 

 

 

 //初始化结构体
            //student st = new student();
            //st.no = 20001;
            //st.name = "张三";
            //st.sex = "男";
            //st.score = 80;
            ////将每个人的信息放进ArrayList集合中,面向对象的思想.
            //ArrayList al = new ArrayList();
            //al.Add(st);
            //student st1 = new student();
            //st1.no = 20002;
            //st1.name = "李四";
            //st1.sex = "女";
            //st1.score = 60;
            //al.Add(st1);

            //ArrayList al = new ArrayList();
            //Console.Write("请输入班级人数:");
            //int a = int.Parse(Console.ReadLine());
            //for (int i = 0; i < a;i++ )
            //{
            //    student st = new student();
            //    Console.Write("请输入第{0}个人的学号:",i+1);
            //    st.no = int.Parse(Console.ReadLine());
            //    Console.Write("请输入第{0}个人的姓名:", i + 1);
            //    st.name =Console.ReadLine();
            //    Console.Write("请输入第{0}个人的性别:", i + 1);
            //    st.sex = Console.ReadLine();
            //    Console.Write("请输入第{0}个人的分数:", i + 1);
            //    st.score = int.Parse(Console.ReadLine());
            //    al.Add(st);
            //}
            //student st1 = (student)al[3];
            //Console.WriteLine(st1.no);
            //Console.WriteLine(st1.name);
            //Console.WriteLine(st1.sex);
            //Console.WriteLine(st1.score);
            //Console.ReadLine();

 


            //int a = 0;
            //int b = 0;
            //int c = 0;
            //int[] piao = new int[20];
            //for (int i = 0; i<20; i++)
            //{
            //    Console.Write("请输入第{0}个人的投票:",i+1);
            //     piao[i]=int.Parse(Console.ReadLine());
            //}
            //for (int j = 0; j < 20; j++)
            //{
            // if(piao [j]==1)
            // {
            //     a += 1;
            // }
            // else if (piao[j] == 2)
            // {
            //     b += 1;
            // }
            // else if (piao[j] == 3)
            // {
            //     c += 1;
            // }
            // else 
            // {
            //     Console.WriteLine("弃权!");
            // }

            //}
            //double d = a > b ? a : b;
            //double e = d > c ? d : c;
            //if(e==a)
            //{
            //    Console.WriteLine("张三当选为班长.");
            //}
            //else if(e==b)
            //{
            //    Console.WriteLine("李四当选为班长.");
            //}
            //else
            //{
            //    Console.WriteLine("王五当选为班长.");
            //}
            //Console.ReadLine();


            Console.Write("请输入班级人数:");
            int num = int.Parse(Console.ReadLine());
            stu st = new stu();
            ArrayList al = new ArrayList();
            double sx = 0;
            double yw = 0;
            for (int i = 0; i < num; i++)
            {
                Console.Write("请输入第{0}个人的姓名:", i + 1);
                st.name = Console.ReadLine();
                Console.Write("请输入第{0}个人的语文成绩:", i + 1);
                st.yu = double.Parse(Console.ReadLine());
                Console.Write("请输入第{0}个人的数学成绩:", i + 1);
                st.shu = double.Parse(Console.ReadLine());
                Console.Write("请输入第{0}个人的英语成绩:", i + 1);
                st.ying = double.Parse(Console.ReadLine());
                yw += st.yu;
                sx += st.shu;
                al.Add(st);

            }
            Console.WriteLine("语文总分是:{0},数学平均分是:{1}", yw, sx / num);
            stu st1 = new stu();
            double[] yy = new double[num];
            string[] mz = new string[num];
            double[] sx1 = new double[num];
            double[] yw1 = new double[num];
            for (int m = 0; m < num; m++)
            {

                st1 = (stu)al[m];
                yy[m] = st1.ying;
                yw1[m] = st1.yu;
                sx1[m] = st1.shu;
                mz[m] = st1.name;
            }
            for (int j = 0; j < num; j++)
            {
                for (int k = j; k < num - 1; k++)
                {
                    if (yy[j] < yy[k + 1])
                    {
                        double zhong = yy[j];
                        yy[j] = yy[k + 1];
                        yy[k + 1] = zhong;
                        string zhong1 = mz[j];
                        mz[j] = mz[k + 1];
                        mz[k + 1] = zhong1;
                        double zhong2 = yw1[j];
                        yw1[j] = yw1[k + 1];
                        yw1[k + 1] = zhong2;
                        double zhong3 = sx1[j];
                        sx1[j] = sx1[k + 1];
                        sx1[k + 1] = zhong3;
                    }
                }

            }
            Console.WriteLine("英语最高分的同学是{0},他的语文分为{1},数学分为{2},英语分为{3}.英语最低分的同学是{4},他的语文分为{5},数学分为{6},英语分为{7}", mz[0], yw1[0], sx1[0], yy[0], mz[num - 1], yw1[num - 1], sx1[num - 1], yy[num - 1]);
            Console.ReadLine();

 struct car
        {
            public string chexinghao;
            public int jiage;
            public int zhoujv;
            public double youhao;
        }

 

        static void Main(string[] args)
        {
            //定义一个结构体,存放关于车辆的几个信息
            //将所有车的信息都放入集合中
            //车型号            价格(W)    轴距 (mm)         油耗(L/100km)
            //宝马320LI           38              2920                 6.9
            //宝马520LI           43              3108                 7.2
            //宝马730LI           89              3210                 6.3
            //奥迪A4L35TFSI       31              2869                 6.2
            //奥迪A6L30TFSI       43              3012                 7.6
            //奥迪A8L45TFSI       89              3122                 8.1
            //奔驰C200L           35              2920                 6.1
            //奔驰E260L           48              3014                 6.7
            //奔驰S320L           93              3165                  8


            //ArrayList al = new ArrayList();
            //car c = new car();
            //c.chexinghao = "宝马320LI";
            //c.jiage = 38;
            //c.zhoujv = 2920;
            //c.youhao = 6.9;
            //al.Add(c);
            //car c1 = new car();
            //c1.chexinghao = "宝马520LI";
            //c1.jiage = 43;
            //c1.zhoujv = 3108;
            //c1.youhao = 7.2;
            //al.Add(c1);
            //car c2 = new car();
            //c2.chexinghao = "宝马730LI";
            //c2.jiage = 89;
            //c2.zhoujv = 3210;
            //c2.youhao = 6.3;
            //al.Add(c2);
            //car c3 = new car();
            //c3.chexinghao = "奥迪A4L35TFSI";
            //c3.jiage = 31;
            //c3.zhoujv = 2869;
            //c3.youhao = 6.2;
            //al.Add(c3);
            //car c4 = new car();
            //c4.chexinghao = "奥迪A6L30TFSI";
            //c4.jiage = 43;
            //c4.zhoujv = 3012;
            //c4.youhao = 7.6;
            //al.Add(c4);
            //car c5 = new car();
            //c5.chexinghao = "奥迪A8L45TFSI ";
            //c5.jiage = 89;
            //c5.zhoujv = 3122;
            //c5.youhao = 8.1;
            //al.Add(c5);
            //car c6 = new car();
            //c6.chexinghao = "奔驰C200L";
            //c6.jiage = 35;
            //c6.zhoujv = 2920;
            //c6.youhao = 6.1;
            //al.Add(c6);
            //car c7 = new car();
            //c7.chexinghao = "奔驰E260L";
            //c7.jiage = 48;
            //c7.zhoujv = 3014;
            //c7.youhao = 6.7;
            //al.Add(c7);
            //car c8 = new car();
            //c8.chexinghao = "奔驰S320L";
            //c8.jiage = 93;
            //c8.zhoujv = 3165;
            //c8.youhao = 8;
            //al.Add(c8);

 


            //现在想买一辆价格在50万以内的车,请给出车的型号以及价格
            //car cc = new car();
            //for (int i = 0; i < 9; i++)
            //{
            //    cc = (car)al[i];
            //    if (cc.jiage < 50)
            //    {
            //        Console.WriteLine("车型号:{0},价格{1}万元.", cc.chexinghao, cc.jiage);
            //    }
            //}

 

 

 

            //买得起豪车,可是很关心油耗,给查一下油耗最低的三辆车的型号以及油耗情况

            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.youhao < cc1.youhao)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc2 = (car)al[8];
            //car cc3 = (car)al[7];
            //car cc4 = (car)al[6];
            //Console.WriteLine("油耗最低的三辆车是:{0}、{1}、{2}。油耗分别为:{3}L/100km、{4}L/100km、{5}L/100km。", cc2.chexinghao, cc3.chexinghao, cc4.chexinghao, cc2.youhao, cc3.youhao, cc4.youhao);

 

 

 


            //买了车之后后座会经常坐人,所有我现在想要轴距大一些的车,前三名即可
            //要列出车的型号以及车的轴距 ..
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.zhoujv < cc1.zhoujv)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc2 = (car)al[0];
            //car cc3 = (car)al[1];
            //car cc4 = (car)al[2];
            //Console.WriteLine("轴距前三的车型号为:{0}、{1}、{2},轴距分别为{3}mm、{4}mm、{5}mm。", cc2.chexinghao, cc3.chexinghao, cc4.chexinghao, cc2.zhoujv, cc3.zhoujv, cc4.zhoujv);

 

 

 

 


            //有钱就是任性,就买最贵的,不买最好的,直接调出来最贵的车的所有信息
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();
            //   
            //    for (int j = i; j < 8; j++)
            //    {         
            //cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.jiage < cc1.jiage)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc2 = (car)al[0];
            //Console.WriteLine("车型号{0},价格{1}万元,轴距{2}mm,油耗{3}L/100km.", cc2.chexinghao, cc2.jiage, cc2.zhoujv, cc2.youhao);

 

 

 


            //本店有哪几款宝马车??列出来所有信息
            //car cc = new car();
            //for (int i = 0; i < 9; i++)
            //{
            //    cc = (car)al[i];
            //    if (cc.chexinghao.Contains("宝马"))
            //    {
            //        Console.WriteLine("车型号{0},价格{1}万元,轴距{2}mm,油耗{3}L/100km.", cc.chexinghao, cc.jiage, cc.zhoujv, cc.youhao);

            //    }

            //}

 

 

 

            //本店奔驰车里面油耗最低的是哪一个?所有信息
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.youhao > cc1.youhao)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //for (int k = 0; k < 9; k++)
            //{
            //    car cc2 = (car)al[k];
            //    if (cc2.chexinghao.Contains("奔驰"))
            //    {
            //        Console.WriteLine("奔驰车中油耗最低为{0},价格为{1}万元,轴距为{2}mm,油耗为{3}L/100km.", cc2.chexinghao, cc2.jiage, cc2.zhoujv, cc2.youhao);
            //        break;
            //    }

            //}

 

 

            //本店在售车辆中轴距最长的是不是奥迪??
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();
            //  
            //    for (int j = i; j < 8; j++)
            //    {         
            //cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.zhoujv < cc1.zhoujv)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc2 = (car)al[0];
            //if (cc2.chexinghao.Contains("奥迪"))
            //{
            //    Console.WriteLine("轴距最长的是奥迪.");
            //}
            //else
            //{
            //    Console.WriteLine("轴距最长的不是奥迪.");
            //}

 

 


            //本店在售车辆轴距最长的是不是油耗最高的??
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.zhoujv < cc1.zhoujv)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc2 = (car)al[0];
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();
            //    cc = (car)al[i];
            //    for (int j = i; j < 8; j++)
            //    {
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.youhao < cc1.youhao)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //car cc3 = (car)al[0];
            //if (cc3.chexinghao == cc2.chexinghao)
            //{
            //    Console.WriteLine("轴距最长的车是油耗最高的车.");
            //}
            //else
            //{
            //    Console.WriteLine("轴距最长的车不是油耗最高的车.");
            //}

 

 

 

            //奔驰车中轴距最长的是哪一辆??
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.zhoujv < cc1.zhoujv)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //for (int k = 0; k < 9; k++)
            //{
            //    car cc2 = (car)al[k];
            //    if (cc2.chexinghao.Contains("奔驰"))
            //    {
            //        Console.WriteLine("奔驰车中轴距最长为{0}.", cc2.chexinghao);
            //        break;
            //    }
            //}

 

 

 


            //就只喜欢宝马,可是没多少钱,请列出来现有车辆中最便宜的宝马车的所有信息
            //for (int i = 0; i < 9; i++)
            //{
            //    car cc = new car();

            //    for (int j = i; j < 8; j++)
            //    {
            //        cc = (car)al[i];
            //        car cc1 = new car();
            //        cc1 = (car)al[j + 1];
            //        if (cc.jiage > cc1.jiage)
            //        {
            //            object zhong = al[i];
            //            al[i] = al[j + 1];
            //            al[j + 1] = zhong;
            //        }
            //    }
            //}
            //for (int k = 0; k < 9; k++)
            //{
            //    car cc2 = (car)al[k];
            //    if (cc2.chexinghao.Contains("宝马"))
            //    {
            //        Console.WriteLine("宝马车中最便宜为{0},价格为{1}万元,轴距为{2}mm,油耗为{3}L/100km.", cc2.chexinghao, cc2.jiage, cc2.zhoujv, cc2.youhao);
            //        break;
            //    }

            //}

 

            //Console.ReadLine();

posted @ 2016-08-03 16:59  王站住  阅读(189)  评论(0编辑  收藏  举报