标签:
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();
}
}
标签:
原文地址:http://www.cnblogs.com/Mr-xue/p/4423428.html