using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace text_1
{
public class Student
{
public string SName
{
get;
set;
}
public double DScore
{
get;
set;
}
public double TScore
{
get;
set;
}
public double XScore
{
get;
set;
}
public double ZScore
{
get;
set;
}
public double getAverageScore()
{
ZScore = DScore * 0.2 + TScore * 0.1 + XScore * 0.7;
return ZScore;
}
public void displayInfo()
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4})",
SName,DScore,TScore,XScore,ZScore );
}
}
class Program
{
static void Main(string[] args)
{
Array arrStudent = Array.CreateInstance(typeof(Student),5);
Array arrScore = Array.CreateInstance(typeof(double), 5);
for (int i = 0;i<5 ; i++)
{
Student st = new Student();
Console.WriteLine("請輸入學生的姓名: \n");
st.SName = Console.ReadLine();
Console.WriteLine("請輸入學生{0}的德育成績: \n",st.SName);
st.DScore = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("請輸入學生{0}的體育成績:\ n", st.SName);
st.TScore = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("請\輸\入\學\生{0}的學習成績: \n", st.SName);
st.XScore = Convert.ToDouble(Console.ReadLine());
arrScore.SetValue(st.getAverageScore(),i);
arrStudent.SetValue(st, i);
}
Array.Sort(arrScore,arrStudent );
Array.Reverse(arrStudent);
Console.WriteLine("學生排名如下: ");
Console.WriteLine("姓名\t體育\t學習\t總評");
for(int i = 0;i<5;i++)
{
Student st = (Student)arrStudent.GetValue(i);
st.displayInfo();
}
}
}
}
C#--利用Array類實現:計算總評成績
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.