C#基礎-033 建立一個學員類,並設計三個欄位用於表示學生的成績(語文、數學、英語);然後定義一個數組表示一個班的學生(10人),依次輸入每個學生的資訊和成績,輸入的同時將學員的每科成績劃分等級
阿新 • • 發佈:2018-12-25
class Student
{
public double _chineseScore;
public double _mathScore;
public double _englishScore;
public string _name;
public char _chineseLevel;
public char _mathLevel;
public char _englishLevel;
public Student()
{
}
public Student(string _name, double _chineseScore, double _mathScore, double _englishScore)
{
this._chineseScore = _chineseScore;
this._mathScore = _mathScore;
this._englishScore = _englishScore;
this._name = _name;
}
public void ShowInformation ()
{
Console.WriteLine("語文{0}分,數學{1}分,英語{2}分", _chineseScore, _mathScore, _englishScore);
}
public void ShowStudentInfo()
{
Console.WriteLine("{0}:\t語文{1}分\t數學{2}分\t英語{3}分\t總分為:{4}\t平均分為:{5}", _name, _chineseScore, _mathScore, _englishScore, SumScore(), Average());
}
public char Level(double score)
{
switch ((int)score / 10)
{
case 10:
return 'A';
case 9:
return 'A';
case 8:
return 'B';
case 7:
return 'C';
case 6:
return 'D';
case 5:
case 4:
case 3:
case 2:
case 1:
return 'E';
default:
return ' ';
}
}
public double SumScore()
{
return _chineseScore + _mathScore + _englishScore;
}
public double Average()
{
return SumScore() / 3;
}
}
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Student[] stu = new Student[10];
for (int i = 0; i < stu.Length; i++)
{
stu[i] = new Student("小茗" + i , r.Next(50, 101), r.Next(70, 101), r.Next(80, 101));
}
Show(stu);
Console.ReadKey();
}
}