private static string[] Exercises(int Range, int Operators, int OperatorsClass, string[] calculation, string[] performance, bool Random_Decimal) { List <string> Result = new List <string>(); string Formula = "", Formulanum = ""; double number1 = Random_Number(Random_Decimal, Range); //随机一个初始数 int OP = number.Next(0, Operators); //随机运算符数量 Formulanum = Formula += number1; for (int j = 0; j <= OP; j++) { int opnext = number.Next(0, OperatorsClass); //随机一个符号 double number2 = Random_Number(Random_Decimal, Range); //随机一个数 if (opnext == 3 && number2 == 0) //判断算式是否存在除0 { number2 = Random_Number(Random_Decimal, Range); //重新随机一个数 } Formula += calculation[opnext] + number2; Formulanum += performance[opnext] + number2; if (Condition(Range, Operators, OperatorsClass, calculation, performance, ref Formula, ref Formulanum, Random_Decimal)) { break; } } Result.Add(Formulanum); Result.Add(Formula); Result.Add(CM10.Shunting(Formulanum).ToString()); return(Result.ToArray()); }
/// <summary> /// 产生分数的题目和结果 /// </summary> /// <param name="Range">范围</param> /// <param name="Operators">符号数</param> /// <param name="OperatorsClass">符号类型</param> /// <param name="calculation"></param> /// <param name=" IsDecimal"></param> /// <returns></returns> public static string[] Exercises_Fraction(int Operators, string[] OperatorsClass, string[] calculation, bool IsDecimal, bool IsFraction, bool IsInvolution) { List <string> Result = new List <string>(); string Formula = ""; number1 = Random_Fraction(); //随机一个初始数 int OP = number.Next(0, Operators); //随机运算符数量 Formula += number1; Splicing_Fraction(Operators, OperatorsClass, calculation, IsDecimal, ref Formula, OP); Result.Add(Formula); Result.Add(CM10.Shunting(Formula).ToString()); return(Result.ToArray()); }
/// <summary> /// 对分数进行判断 /// </summary> /// <param name="Operators"></param> /// <param name="OperatorsClass"></param> /// <param name="calculation"></param> /// <param name="Formula"></param> /// <param name="IsInvolution"></param> /// <returns></returns> private static bool Condition_Fraction(int Operators, string[] OperatorsClass, string[] calculation, ref string Formula, bool IsInvolution) { if (!negative_fraction(CM10.Shunting(Formula).ToString()) || !IsDouble(CM10.Shunting(Formula).ToString()) && IsInvolution) { string[] es = Exercises_Fraction(Operators, OperatorsClass, calculation, IsInvolution, false, false); Formula = es[0]; return(true); } if (!IsNumber(CM10.Shunting(Formula).ToString()) && !IsInvolution) { string[] es = Exercises_Fraction(Operators, OperatorsClass, calculation, IsInvolution, false, false); Formula = es[0]; return(true); } return(false); }
/// <summary> /// 重构判断题目计算过程中是否有负数或除0 /// </summary> /// <param name="Range"></param> /// <param name="Operators"></param> /// <param name="OperatorsClass"></param> /// <param name="calculation"></param> /// <param name="performance"></param> /// <param name="Formula"></param> /// <param name="Formulanum"></param> /// <param name=" IsDecimal"></param> /// <returns></returns> private static bool Condition(int Range, int Operators, string[] OperatorsClass, string[] calculation, ref string Formula, bool IsDecimal) { if (Convert.ToDouble(CM10.Shunting(Formula).ToString()) < 0 || !IsDouble(CM10.Shunting(Formula).ToString()) && IsDecimal) { string[] es = Exercises(Range, Operators, OperatorsClass, calculation, IsDecimal, false, false); Formula = es[0]; return(true); } if (!IsNumber(CM10.Shunting(Formula).ToString()) && !IsDecimal) { string[] es = Exercises(Range, Operators, OperatorsClass, calculation, IsDecimal, false, false); Formula = es[0]; return(true); } return(false); }
/// <summary> /// 产生题目和结果 /// </summary> /// <param name="Range"></param> /// <param name="Operators"></param> /// <param name="OperatorsClass"></param> /// <param name="calculation"></param> /// <param name="performance"></param> /// <param name=" IsDecimal"></param> /// <returns></returns> private static string[] Exercises(int Range, int Operators, int OperatorsClass, string[] calculation, string[] performance, bool IsDecimal) { List <string> Result = new List <string>(); string Formula = "", Formulanum = ""; if (IsDecimal == true) { number1 = Random_Number(IsDecimal, Range); //随机一个初始数 } int OP = number.Next(0, Operators); //随机运算符数量 Formulanum = Formula += number1; Splicing(Range, Operators, OperatorsClass, calculation, performance, IsDecimal, ref Formula, ref Formulanum, OP); Result.Add(Formulanum); Result.Add(Formula); Result.Add(CM10.Shunting(Formulanum).ToString()); return(Result.ToArray()); }
/// <summary> /// 重构判断题目计算过程中是否有负数或除0 /// </summary> /// <param name="Range"></param> /// <param name="Operators"></param> /// <param name="OperatorsClass"></param> /// <param name="calculation"></param> /// <param name="performance"></param> /// <param name="Formula"></param> /// <param name="Formulanum"></param> /// <param name=" IsDecimal"></param> /// <returns></returns> private static bool Condition(int Range, int Operators, int OperatorsClass, string[] calculation, string[] performance, ref string Formula, ref string Formulanum, bool IsDecimal) { if (Convert.ToDouble(CM10.Shunting(Formulanum).ToString()) < 0 || !IsDouble(dt.Compute(Formulanum, "null").ToString()) && IsDecimal) { string[] es = Exercises(Range, Operators, OperatorsClass, calculation, performance, IsDecimal); Formulanum = es[0]; Formula = es[1]; return(true); } if (!IsNumber(dt.Compute(Formulanum, "null").ToString()) && !IsDecimal) { string[] es = Exercises(Range, Operators, OperatorsClass, calculation, performance, IsDecimal); Formulanum = es[0]; Formula = es[1]; return(true); } return(false); }
/// <summary> /// 产生题目和结果 /// </summary> /// <param name="Range">范围</param> /// <param name="Operators">符号数</param> /// <param name="OperatorsClass">符号类型</param> /// <param name="calculation"></param> /// <param name=" IsDecimal"></param> /// <returns></returns> private static string[] Exercises(int Range, int Operators, string[] OperatorsClass, string[] calculation, bool IsDecimal, bool IsFraction, bool IsInvolution) { List <string> Result = new List <string>(); string Formula = ""; number1 = Random_Number(IsDecimal, Range).ToString(); //随机一个初始数 int OP = number.Next(0, Operators); //随机运算符数量 Formula += number1; Splicing(Range, Operators, OperatorsClass, calculation, IsDecimal, ref Formula, OP); int lbo = number.Next(1, 4); if (IsInvolution && lbo == 2) { Formula = Involution.Generate(Formula, Operators); } Result.Add(Formula); Result.Add(CM10.Shunting(Formula).ToString()); return(Result.ToArray()); }