C#做一年小孩做一个口算题生成器

孩子上小学,老师要求孩子每天做40到口算题,于是编写了一个口算题生成器,还真的挺好用的!!

其实非常简单,就是制作了一个ExerciseMaker类,

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

namespace MathExercise
{
    class ExerciseMaker
    {
        int ExerciseLevel = 21;//运算难度
        List<String> Exam; 

        //
        public bool MakeOne(out String s)
        {
            //+,-,++,--, +-,-+,生成一个0~5的随机数分别表示运算的类型
            Random op_type = new Random();
            int op1 = op_type.Next(0, 6);

            //根据生成的运算符进行出题,生成响应的题
            int opOne = op_type.Next(0, ExerciseLevel);
            int opTwo = op_type.Next(0, ExerciseLevel);
            int opThree = op_type.Next(0, ExerciseLevel);
            int opAdd = opOne + opTwo;
            if (opAdd >= ExerciseLevel)
            {
                opOne = opOne / 2;
                opTwo = opTwo / 2;
                opAdd = opOne + opTwo;
            }
            int opMax = Math.Max(opOne, opTwo);
            int opMin = Math.Min(opOne, opTwo);
            
            switch (op1)
            {
                case 0://+
                    s = opOne.ToString() + "+" + opTwo.ToString() + "=";
                    return true;                    
                case 1://-
                    s = opMax.ToString() + "-" + opMin.ToString() + "=";
                    return true;
                case 2://++
                    if (opOne + opTwo + opThree >= ExerciseLevel)
                    {
                        opOne = opOne / 3;
                        opTwo = opTwo / 3;
                        opThree = opThree / 3;
                    }
                    s = opOne.ToString() + "+" + opTwo.ToString() + "+" + opThree.ToString() +"=";
                    return true;
                case 3://--
                    //int opThreerange = (ExerciseLevel - opAdd);
                    opThree = op_type.Next(opAdd,ExerciseLevel);
                    s = opThree.ToString() + "-" + opTwo.ToString() + "-" + opOne.ToString() + "=";
                    return true;
                case 4://+-
                    if (opAdd < opThree)
                    {
                        opThree = op_type.Next(0, opAdd);
                    }
                    s = opOne.ToString() + "+" + opTwo.ToString() + "-"+opThree.ToString() + "=";
                    return true;
                case 5://-+
                    if (opMax - opMin + opThree >= ExerciseLevel)
                    { 
                        opThree = op_type.Next(0, ExerciseLevel -  opMax + opMin);
                    }
                    s = opMax.ToString() + "-" + opMin.ToString() + "+"+opThree.ToString() + "=";
                    return true;
                default:
                    break;
            }
            s = "";
            return false;
        }

        public bool MakeExam(UInt16 ExerciseNum)
        {
            Exam = new List<string>();

            int count = 0;
            for (UInt16 i = 0; i < ExerciseNum; i++)
            {
                String ex = new String("???");
                if(MakeOne(out ex))
                { 
                    Exam.Add(ex);
                    count++;
                }
            }

            if (count == ExerciseNum)
            {
                return true;
            }
            return false;
        }

        public List<String> GetExam()
        {
            return Exam;
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值