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

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();
        }
    }
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值