c#????????

ljb07976513524 2009-03-23 06:07:00
各位大侠。。
我想输入姓名,分数后,然后打印出来;
接下来求平均分,能够根据平均分来排名。



string[] lin =new string[3] {"英语","数学","c#"};
for (int i = 0; i < 5; i++)
{
Console.WriteLine("请输入您的姓名-------: {0}", i + 1);
name[i] = Convert.ToString(Console.ReadLine());
for (int j = 0; j < 3; j++)
{
Console.WriteLine("分别输入英语成绩:{0}",lin[j]);//引入课程;
num[i, j] = Convert.ToInt32(Console.ReadLine());//引入分数;

}


}
...全文
135 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
kbtjh 2009-03-24
  • 打赏
  • 举报
回复
学习一下
xyrdqq 2009-03-23
  • 打赏
  • 举报
回复
我只是一个刚接触C#的人啦
所以我看到你们这么厉害
我好惭愧啊
聖少俊 2009-03-23
  • 打赏
  • 举报
回复
学习
fanbo 2009-03-23
  • 打赏
  • 举报
回复
高手何其多啊。
其实你去看看msdn最好了。
birdlonger 2009-03-23
  • 打赏
  • 举报
回复
实现ICoparable接口实现类型按照自己定义的比较方式,顺序排列 ,此处实现按平均分由高到低排列
public class Student : IComparable
{
private string _name;
private int _math;
private int _chinese ;
private int _cshape ;
private double _average ;
public Student(string name, int m, int c, int cs)
{
this._name = name;
this._math = m;
this._chinese = c;
this._cshape = cs;
this._average = (m + c + cs) / 3;
}
public int CompareTo (object o) //此处实现排序规则,
{
Student st = (Student)o;
if (st._average > this._average)
return 1;
else if (st._average == this._average)
return 0;
else
return -1;
}
public override string ToString()
{
return this._name + "\t\t" + this._average.ToString();
}
}

// using System.Collections;
class Program
{
static void Main(string[] args)
{
ArrayList studentlist = new ArrayList(5); //使用ArrayList 需添加 , using System.Collections;
studentlist.Add(new Student("小王", 90, 80, 85));
studentlist.Add(new Student("小于", 80, 85, 73));
studentlist.Add(new Student("小丽", 95, 90, 85));
studentlist.Add(new Student("李", 80, 60, 70));
studentlist.Add(new Student("陈", 80, 85, 92));
foreach (Student s in studentlist )
{
Console.WriteLine (s.ToString());
}
Console.WriteLine("-------------------------------------------");
studentlist.Sort();
foreach (Student s in studentlist)
{
Console.WriteLine(s.ToString());
}
Console.ReadLine();
}
}
gisyellow 2009-03-23
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IList<Student> lstStudents = new List<Student>();

for (int i = 0; i < 3; i++)
{
Student student = new Student();
Console.WriteLine("请输入姓名:");
student.Name = Console.ReadLine();
Console.WriteLine("请输入英语成绩:");
student.English = double.Parse(Console.ReadLine());
Console.WriteLine("请输入数学成绩:");
student.Math = double.Parse(Console.ReadLine());
Console.WriteLine("请输入C#成绩:");
student.CSharp = double.Parse(Console.ReadLine());
student.Average = student.CaclAverage();//计算平均分
lstStudents.Add(student);
}

foreach (Student stu in lstStudents)
{
Console.WriteLine("姓名:" + stu.Name + ";英语:" + stu.English +
";数学:" + stu.Math + ";C#:" + stu.CSharp + ";平均分:" + stu.Average);
}

//按平均分降序排序
for (int i = 0; i < lstStudents.Count - 1; i++)
{
for (int j = 1; j < lstStudents.Count; j++)
{
Student tempStudent = null;
if (lstStudents[i].Average < lstStudents[j].Average)
{
tempStudent = lstStudents[j];
lstStudents[j] = lstStudents[i];
lstStudents[i] = tempStudent;
}
}
}

foreach (Student stu in lstStudents)
{
Console.WriteLine("姓名:{0};平均分:{1}", stu.Name, stu.Average);
}

Console.ReadLine();
}

}

class Student
{
public string Name;
public double English;
public double Math;
public double CSharp;
public double Average;//平均分

//计算平均分
public double CaclAverage()
{
//实际应用中注意检查数据是否合理
double dSum = English + Math + CSharp;
return dSum / 3;
}

public override string ToString()
{
return Name;
}
}
}

马老虎 2009-03-23
  • 打赏
  • 举报
回复
2维数组
ljb07976513524 2009-03-23
  • 打赏
  • 举报
回复
兄弟啊。。。
具体一点啊。。。。
颤菊大师 2009-03-23
  • 打赏
  • 举报
回复
Dictionary<key,value>
wuyq11 2009-03-23
  • 打赏
  • 举报
回复
num[i, j] 为5行4列,最后一列保存平均分
ljb07976513524 2009-03-23
  • 打赏
  • 举报
回复
如果实现平均分排序。。
姓名分数也要跟这移动。。。

PandaIT 2009-03-23
  • 打赏
  • 举报
回复
用sort吧
ljb07976513524 2009-03-23
  • 打赏
  • 举报
回复
我已经计算出平均分来了;
但不知道怎样利用平均分来排名;
for (int i = 0; i < 5; i++)
{

for (int j = 0; j < 3; j++)
{

sum[i] += num[i, j];
}



Console.WriteLine();

}


//接下来求平均分

Console.WriteLine("姓名----英语--------数学--------c#--------平均分-----");
for (int i = 0; i < 5; i++)
{

Console.Write("{0,-10}", name[i]);//输出姓名;

for (int j = 0; j < 3; j++)
{
Console.Write("{0,-10}",num[i,j]);


}

Console.Write("{0,-20}", sum[i] / 3);

Console.WriteLine();
}
//接下来是排名的过程;
whoami333 2009-03-23
  • 打赏
  • 举报
回复
你还需要一个数组计算平均分。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧