C#基础-033 创建一个学员类,并设计三个字段用于表示学生的成绩(语文、数学、英语);然后定义一个数组表示一个班的学生(10人),依次输入每个学生的信息和成绩,输入的同时将学员的每科成绩划分等级

xiaoxiao2021-02-28  77

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(); } }
转载请注明原文地址: https://www.6miu.com/read-64378.html

最新回复(0)