/// <summary> /// 關係運算符轉換為對應的字符編碼 /// </summary> /// <param name="operation">運算符(大於小於等於)</param> /// <returns>字符編碼</returns> public static string ToSignOfCompareUnicode(this SignOfCompare operation) { var flag = string.Empty; switch (operation) { // = case SignOfCompare.Equal: flag = "="; break; // > case SignOfCompare.Greater: flag = ">"; break; // < case SignOfCompare.Less: flag = "<"; break; default: break; } return(flag); }
/// <summary> /// 判定是否需要反推并重新作成計算式 /// </summary> /// <remarks> /// 情況1:左邊等式小於右邊等式時,左邊等式結果已經到達最大計算結果值 /// 情況2:左邊等式大於右邊等式時,左邊等式結果是0 /// </remarks> /// <param name="sign">左側水果計算式集合</param> /// <param name="leftFormula">計算結果值</param> /// <param name="maximumLimit"></param> /// <returns>需要反推:true 正常情況: false</returns> private bool CheckIsNeedInverseMethod(SignOfCompare sign, Formula leftFormula, int maximumLimit) { // 情況1 if (sign == SignOfCompare.Less && leftFormula.Answer == maximumLimit) { return(true); } // 情況2 if (sign == SignOfCompare.Greater && leftFormula.Answer == 0) { return(true); } return(false); }
/// <summary> /// 題型構築 /// </summary> /// <param name="p">題型參數</param> /// <param name="signFunc">運算符取得用的表達式</param> /// <returns></returns> private bool MarkFormulaList(FindNearestNumberParameter p, Func <SignOfOperation> signFunc) { // 关系運算式的左側計算式(指定單個運算符實例) Formula leftFormula = MakeLeftFormula(p.MaximumLimit, signFunc); // 關係運算符中隨機抽取一個(只限於大於和小於符號) SignOfCompare compare = CommonUtil.GetRandomNumber(SignOfCompare.Greater, SignOfCompare.Less); // 小於符號推算=》右邊等式結果:左邊等式運算結果加一:左邊等式運算結果減一 var rightAnswer = (compare == SignOfCompare.Less) ? leftFormula.Answer + 1 : leftFormula.Answer - 1; // 判斷是否需要回滾當前算式 if (CheckIsNeedInverseMethod(compare, leftFormula, p.MaximumLimit)) { return(false); } // 关系運算式的右側計算式(指定單個運算符實例) Formula rightFormula = MakeRightFormula(p.MaximumLimit, rightAnswer, signFunc); // 在關係運算式中(左側或者右側計算式)隨機確定填空項目所在位置 bool isLeftFormula = CommonUtil.GetRandomNumber(GapFilling.Left, GapFilling.Right) == GapFilling.Left; if (isLeftFormula) { // 在等式左邊的數里隨機選擇一個作為填空項目 leftFormula.Gap = CommonUtil.GetRandomNumber(GapFilling.Left, GapFilling.Right); } else { // 在等式右邊的數里隨機選擇一個作為填空項目 rightFormula.Gap = CommonUtil.GetRandomNumber(GapFilling.Left, GapFilling.Right); } // 計算式作成 p.Formulas.Add(new NearestNumberFormula() { LeftFormula = leftFormula, RightFormula = rightFormula, Answer = compare }); return(true); }
/// <summary> /// 算式作成 /// </summary> /// <param name="p">題型參數</param> public override void MarkFormulaList(NumericSortingParameter p) { // 出題數量 for (int i = 0; i < p.NumberOfQuestions; i++) { List <int> numberList = new List <int>(); List <int> answerList = new List <int>(); // 參與數字排序的對象個數 for (int j = 0; j < p.Numbers; j++) { numberList.Add(GetNumberWithSort(numberList, p.MaximumLimit)); } // 關係運算符(隨機獲取) SignOfCompare sign = CommonUtil.GetRandomNumber(SignOfCompare.Greater, SignOfCompare.Less); // 如果是大於符號 if (sign == SignOfCompare.Greater) { // 以降序方式排列數組并作為答案保存 numberList.Sort((x, y) => - x.CompareTo(y)); } else { // 以升序方式排列數組并作為答案保存 numberList.Sort(); } answerList = numberList; p.Formulas.Add(new NumericSortingFormula() { // 關係運算符 Sign = sign, // 排序數字串(亂序) NumberList = numberList.OrderBy(x => Guid.NewGuid()).ToList(), // 答案數字串(已排序) AnswerList = answerList }); } }
/// <summary> /// 關係運算符enum轉圖片名稱(HTML圖片顯示使用) /// </summary> /// <param name="operation">運算符(大於小於等於)</param> /// <returns>圖片名稱</returns> public static string ToSignOfCompareEnString(this SignOfCompare operation) { var flag = string.Empty; switch (operation) { case SignOfCompare.Equal: flag = "calculator"; break; case SignOfCompare.Greater: flag = "char-more"; break; case SignOfCompare.Less: flag = "char-less"; break; default: break; } return(flag); }
/// <summary> /// 關係運算符轉換為對應的字符編碼 /// </summary> /// <param name="operation">運算符(大於小於等於)</param> /// <returns>字符編碼</returns> public static string ToSignOfCompareString(this SignOfCompare operation) { var flag = string.Empty; switch (operation) { case SignOfCompare.Equal: flag = "="; break; case SignOfCompare.Greater: flag = ">"; break; case SignOfCompare.Less: flag = "<"; break; default: break; } return(flag); }