码迷,mamicode.com
首页 > 编程语言 > 详细

struct 数组

时间:2015-04-13 22:50:48      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

 

 class Program  

 {   

      struct xs                                                          //自定义xs类型

     {

            public int xuehao;                                      //public 共有的

            public string xingming;    

            public double shuxue;    

            public double yuwen;        

            public double waiyu;      

            public double zongfen;    

            public int mingci;           

      }     

    static void Main(string[] args)     

 {   

             xs[] s = new xs[3];                                         //new出新的数组

             for (int i = 0; i <s.Length ; i++)        

       {              

               Console.WriteLine("正在输入第"+(i+1)+"个学生的信息:");     

               s[i].xuehao = i + 1;                       

               Console.Write("请输入姓名:");         

              s[i].xingming = Console.ReadLine();      

               Console.Write("请输入数学分数:");      

               s[i].shuxue =Convert.ToDouble(Console .ReadLine());     

               Console.Write("请输入语文分数:");         

               s[i].yuwen = Convert.ToDouble(Console.ReadLine());          

               Console.Write("请输入外语分数:");           

               s[i].waiyu = Convert.ToDouble(Console.ReadLine());     

               s[i].zongfen = s[i].shuxue + s[i].yuwen + s[i].waiyu;                

       }           

  //排序           冒泡排序

              for (int i = 1; i <= s.Length -1; i++)         

      {              

                  for (int j = 1; j <= s.Length-i ; j++)    

             {                 

                   if ((s[j].zongfen)>(s[j-1].zongfen) )     

                      {                 

                                  xs temp = s[j];         

                                  s[j] = s[j-1];       

                                 s[j - 1] = temp;    

                      }          

             }        

     }         

    //写名次  

        for (int i = 0; i < s.Length; i++)       

       {            

              s[i].mingci = i + 1;      

       }       

      //输出        

       for (int i = 0; i < s.Length ; i++)      

       {        

         Console.WriteLine("姓名:"+s[i].xingming + "\t" +"学号:" +s[i].xuehao + "\t" +"数学:" +s[i].shuxue + "\t" +"语文:"+ s[i].yuwen + "\t" +"外语"+ s[i].waiyu + "\t" +"总分"+s[i].zongfen + "\t" +"名次"+ s[i].mingci);       

       }

            Console.ReadLine();  

       }    

}

struct 数组

标签:

原文地址:http://www.cnblogs.com/Mr-xue/p/4423428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!