private MCQuestion CreateMCQuestion(SectionBaseInfo info, Section section) { valuesStruct valueMC = new valuesStruct(10); //题干展示的值 //随即获得数值 this.GetRandomValues(info, ref valueMC); questionValueList.Add((decimal.ToInt32(valueMC.values[0]))); //生产题干文本 string questionText = QuestionText(valueMC); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int valueLst = (decimal.ToInt32(valueMC.answer)) - 12, valueMst = (decimal.ToInt32(valueMC.answer)) + 12; if (valueLst - 12 <= 1) { valueLst = 1; } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueLst, valueMst, false, (c => (c == decimal.ToInt32(valueMC.answer))), decimal.ToInt32(valueMC.answer))) { optionList.Add(option); } return(optionList); } ); StringBuilder strBuilder = new StringBuilder(); //解题步骤 string Steps = SolveSteps(valueMC); strBuilder.AppendLine(Steps); mcQuestion.Solution.Content = strBuilder.ToString(); section.QuestionCollection.Add(mcQuestion); return(mcQuestion); }
public ActionResult Create([Bind(Include = "id,Question,A,B,C,D,CorrectAnswer,TopicId")] MCQuestion mCQuestion) { if (ModelState.IsValid) { var top = db.Topics.Find(mCQuestion.TopicId); mCQuestion.QuestionTopic = top; top.Questions.Add(mCQuestion); db.MCQuestions.Add(mCQuestion); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Topics = db.Topics.ToList(); return(View(mCQuestion)); }
// GET: MCQuestions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MCQuestion mCQuestion = db.MCQuestions.Find(id); if (mCQuestion == null) { return(HttpNotFound()); } return(View(mCQuestion)); }
internal static MCQuestion CreateMCQuestion(CreateQuestionContentDelegate bodyCallback, CreateQuestionOptionDelegate optionCallback) { MCQuestion mcQuestion = new MCQuestion(); bodyCallback(mcQuestion.Content); foreach (QuestionOption option in optionCallback()) { mcQuestion.QuestionOptionCollection.Add(option); } mcQuestion.RandomOption = false; return(mcQuestion); }
// GET: MCQuestions/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MCQuestion mCQuestion = db.MCQuestions.Find(id); if (mCQuestion == null) { return(HttpNotFound()); } ViewBag.Topics = db.Topics.ToList(); return(View(mCQuestion)); }
public ActionResult Edit([Bind(Include = "id,Question,A,B,C,D,CorrectAnswer,TopicId")] MCQuestion mCQuestion) { if (ModelState.IsValid) { var top = db.Topics.Find(mCQuestion.TopicId); mCQuestion.QuestionTopic = top; db.Entry(mCQuestion).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Topics = db.Topics.ToList(); return(View(mCQuestion)); }
public MCQuestionUserControl(MCQuestion mcQuestion) { InitializeComponent(); this.mcQuestion = mcQuestion; this.optionListView.ItemsSource = this.tempOptionList; foreach (QuestionOption option in this.mcQuestion.QuestionOptionCollection) { this.tempOptionList.Add(option.Clone() as QuestionOption); } if (this.mcQuestion.Content != null) { this.richTextEditor.Text = this.mcQuestion.Content.Content; } }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int minValue = 1; int maxValue = 10; int j = 2; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } string questionText = "从下面选项中选出分数。"; List <QuestionContentPart> solutionContentPartList = new List <QuestionContentPart>(); QuestionContent solution = new QuestionContent(); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); this.AppendDoubleOption(minValue, maxValue, optionList, solution); this.AppendFractionOption(minValue, maxValue, optionList, solution); optionList[optionList.Count - 1].IsCorrect = true; this.AppendIntegerOption(minValue, maxValue, optionList, solution); return(optionList); } ); mcQuestion.Solution = solution; mcQuestion.RandomOption = true; section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int minValue = 0; int maxValue = 10 + 1; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } string questionText = string.Format("选出是带小数的数。"); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption temp in ObjectCreator.CreateDoubleOption(0, 0, minValue, maxValue)) { optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateIntegerOption(minValue, maxValue)) { optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateDoubleOption(minValue + 1, maxValue + 1, minValue + 1, maxValue)) { temp.IsCorrect = true; optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateDoubleOption(0, 0, minValue + 1, maxValue)) { optionList.Add(temp); } return(optionList); } ); mcQuestion.RandomOption = true; section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; if (content.QuestionPartCollection[0] is ArithmeticDecimalValuePart) { ArithmeticDecimalValuePart decimalPart = content.QuestionPartCollection[0] as ArithmeticDecimalValuePart; decimal value = decimalPart.Value.Value; if (value < 1 && value != 0) { strBuilder.AppendLine(string.Format("{0}是整数部分为零的小数,是纯小数。", value)); } else if (value % 1 != 0) { strBuilder.AppendLine(string.Format("{0}整数部分不为零的小数,是带小数,是正确答案。", value)); } else { strBuilder.AppendLine(string.Format("{0}是整数。", value)); } } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { int minValue = 0; int maxValue = 10000; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } List <int> questionValueList = new List <int>(); Random rand = new Random((int)DateTime.Now.Ticks); int valueA = 0, valueB = 0; int minRand = 0, maxRand = 0; int minValueTmp = minValue, maxValueTmp = maxValue; while (true) { if (minValueTmp / 10 >= 1) { minRand++; minValueTmp /= 10; } else { break; } } while (true) { if (maxValueTmp / 10 >= 1) { maxRand++; maxValueTmp /= 10; } else { break; } } while (true) { valueA = rand.Next(minRand, maxRand + 1); valueB = rand.Next(minRand + 1, maxRand + 1); if (valueA != valueB) { break; } } double valueP1 = System.Math.Pow(10, valueA); double valueP2 = System.Math.Pow(10, valueB); double valueD1 = 1 / valueP1, valueD2 = 1 / valueP2; questionValueList.Add(valueA); string questionText; //int valueC1, valueC2; int multipleD; if (valueD1 > valueD2) { //valueC1 = valueB; //valueC2 = valueA; multipleD = (int)(valueD1 / valueD2); questionText = string.Format("{0}是{1}的几倍。", valueD1, valueD2); } else { //valueC1 = valueA; //valueC2 = valueB; multipleD = (int)(valueD2 / valueD1); questionText = string.Format("{1}是{0}的几倍。", valueD1, valueD2); } MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int valueLst = (int)(System.Math.Pow(10, minRand)), valueMst = (int)(System.Math.Pow(10, maxRand)); if (minRand - 20 <= 0) { valueLst = 0; } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueLst, valueMst, false, (c => (c == multipleD)), multipleD)) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (value == multipleD) { strBuilder.AppendLine(string.Format("{0}和{1}是{2}倍的关系,是正确答案。", valueD1, valueD2, value)); } else { strBuilder.AppendLine(string.Format("{0}和{1}不是{2}倍的关系。", valueD1, valueD2, value)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); decimal valueA = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue + 1); decimal result = valueA + valueB; string questionText = "从下面选项中选出符合加法交换律的等式。"; MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); for (int i = 0; i < 3; i++) { decimal a = rand.Next(minValue, maxValue + 1); decimal b = rand.Next(minValue, maxValue + 1); decimal c = rand.Next(minValue, decimal.ToInt32(a + b + 1)); decimal d = a + b - c; if (d == a || d == b) { d = d == 0 ? d + 1 : d - 1; c = a + b - d; } QuestionOption option = new QuestionOption(); option.OptionContent.Content = string.Format("{0} + {1} = {2} + {3}", a, b, c, d); optionList.Add(option); } QuestionOption correctOption = new QuestionOption(); correctOption.OptionContent.Content = string.Format("{0} + {1} = {1} + {0}", valueA, valueB); correctOption.IsCorrect = true; int correctIndex = rand.Next(100) % 4; if (correctIndex == optionList.Count) { optionList.Add(correctOption); } else { optionList.Insert(correctIndex, correctOption); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("{0}+{1}={1}+{0},在这个等式中,交换两个加数{0}和{1}的位置,和不变,都是{2}。\n是符合加法交换律的,是正确答案。", valueA, valueB, result); section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int minValue = 10; int maxValue = 100; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } int divValue = rand.Next(minValue, maxValue); string questionText = string.Format("请选出至少有两个质因数的数。"); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c) => { int j, k, iFlag = 0; for (j = 2; j < c / 2 + 1; j++) { if (c % j == 0) { iFlag = 0; for (k = 2; k < j / 2 + 1; k++) { if (j % k == 0) { iFlag = 1; break; } } if (iFlag == 0) { return(true); } } } return(false); })) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); int j, k, iFlag = 0, flag = -1; if (value == 0 || value == 1) { flag = 0; } for (j = 2; j < value / 2 + 1; j++) { if (value % j == 0) { if (j == 2) { flag = 1; break; } iFlag = 0; for (k = 2; k < j / 2 + 1; k++) { if (j % k == 0) { iFlag = 1; break; } } if (iFlag == 0) { flag = 1; break; } } } if (flag == 0) { strBuilder.AppendLine(string.Format("0和1都不是质因数。")); } else if (flag == 1) { strBuilder.AppendLine(string.Format("{0}有两个质因数,是正确答案。", value)); } else { strBuilder.AppendLine(string.Format("{0}没有质因数。", value)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int tryCount = 100; while (true) { int minValue = 10; int maxValue = 100; int j = 2; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } int divValue = rand.Next(minValue, maxValue); bool validValue = false; for (j = 3; j <= divValue / 2 + 1; j++) { if (divValue % j == 0) { validValue = true; break; } } tryCount--; if (tryCount == 0) { break; } if (!validValue) { continue; } string questionText = string.Format("请选出自然数{0}的约数。", divValue); int inMinValue = 2, inMaxValue = 10; if (j / 2 > 2) { inMinValue = j / 2; } if (j * 3 > 10) { inMaxValue = j * 3; } MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, inMinValue, inMaxValue, false, (c => ((divValue % c) == 0)))) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (divValue % value == 0) { strBuilder.AppendLine(string.Format("{0}除以{1}等于{2},没有余数,是正确答案。", divValue, value, divValue / value)); } else { strBuilder.AppendLine(string.Format("{0}除以{1}等于{2},余数是{3}。", divValue, value, divValue / (int)(value), divValue % value)); } } mcQuestion.Solution.Content = strBuilder.ToString(); break; } }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); int valueA = 0, valueB = 0, valueC = 0; int value; while (true) { int j2 = 0; valueA = rand.Next(minValue, maxValue); valueB = rand.Next(minValue, maxValue); if (valueA > valueB) { value = valueA; } else if (valueA < valueB) { value = valueB; } else { continue; } j2 = value; while (true) { if (j2 % valueA == 0 && j2 % valueB == 0) { valueC = j2; break; } j2++; } break; } string questionText = string.Format("请选{0}和{1}的最小公倍数。", valueA, valueB); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueC / 2, valueC * 2, false, (c => (c == valueC)), valueC)) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal valueO = System.Convert.ToDecimal(content.Content); if (valueC == valueO) { strBuilder.AppendLine(string.Format("{0}能同时被{1}和{2}整除,且是所有能被整除的数里面最小的数,是正确答案。", valueO, valueA, valueB)); } else { if (valueO % valueA == 0 && valueO % valueB == 0) { strBuilder.AppendLine(string.Format("{0}能同时被{1}和{2}整除,但不是所有能被整除的数里面最小的数。", valueO, valueA, valueB)); } else { strBuilder.AppendLine(string.Format("{0}不能同时被{1}和{2}整除。", valueO, valueA, valueB)); } } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); decimal valueA = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueC = rand.Next(minValue, maxValue + 1); decimal result = valueA + valueB; string questionText = string.Format("从下面选项中选出方程x + {0} = {1} 的解。", valueB, result); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); //for (int i = 0; i < 3; i++) //{ decimal d = rand.Next(minValue, maxValue + 1); if (d == valueA) { d = d == 0 ? d + 1 : d - 1; } QuestionOption option = new QuestionOption(); option.OptionContent.Content = string.Format("{0}", d); optionList.Add(option); //} //int tmpminValue, tmpmaxValue; //if (d <= 2) //{ // tmpminValue = decimal.ToInt32(d) + 1; // tmpmaxValue = maxValue; //} //else //{ // tmpminValue = decimal.ToInt32(d) + 1; // tmpmaxValue = maxValue; //} decimal d1; while (true) { d1 = rand.Next(minValue, maxValue + 1); if (d1 != valueA && d1 != d) { break; } } QuestionOption option1 = new QuestionOption(); option1.OptionContent.Content = string.Format("{0}", d1); optionList.Add(option1); decimal d2; while (true) { d2 = rand.Next(minValue, maxValue + 1); if (d2 != valueA && d2 != d && d2 != d1) { break; } } QuestionOption option2 = new QuestionOption(); option2.OptionContent.Content = string.Format("{0}", d2); optionList.Add(option2); QuestionOption correctOption = new QuestionOption(); correctOption.OptionContent.Content = string.Format("{0}", valueA); correctOption.IsCorrect = true; int correctIndex = rand.Next(100) % 4; if (correctIndex == optionList.Count) { optionList.Add(correctOption); } else { optionList.Insert(correctIndex, correctOption); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("当x={2},方程x + {0} = {1}等式左右两边相等,因此{2}是解方程,是正确答案。", valueB, result, valueA); section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); //int divValue = rand.Next(2, 9); string questionText = string.Format("请选出只能分解出两个质因数相乘的数。"); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int minValue = 10; int maxValue = 100; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c) => { int j, k, iFlag1 = 0, iFlag2 = 0, j2, k2; for (j = 2; j < c / 2 + 1; j++) { if (c % j == 0) { iFlag1 = 0; iFlag2 = 0; for (k = 2; k < j / 2 + 1; k++) { if (j % k == 0) { iFlag1 = 1; break; } } j2 = (int)(c / j); for (k2 = 2; k2 < j2 / 2 + 1; k2++) { if (j2 % k2 == 0) { iFlag2 = 1; break; } } if (iFlag1 == 0 && iFlag2 == 0) { return(true); } } } return(false); })) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); int j, k, iFlag1 = 0, iFlag2 = 0, j2 = 0, k2; int flag = -1; flag = 0; for (j = 2; j < value / 2 + 1; j++) { if (value % j == 0) { iFlag1 = 0; iFlag2 = 0; for (k = 2; k < j / 2 + 1; k++) { if (j % k == 0) { iFlag1 = 1; break; } } j2 = (int)(value / j); for (k2 = 2; k2 < j2 / 2 + 1; k2++) { if (j2 % k2 == 0) { iFlag2 = 1; break; } } if (iFlag1 == 0 && iFlag2 == 0) { flag = 1; break; } } } if (flag == 1) { strBuilder.AppendLine(string.Format("{0}可分解成质因数{1},{2}相乘,是正确答案。", value, j, j2)); } else { strBuilder.AppendLine(string.Format("{0}不能分解质因数。", value)); } } }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int divValue = rand.Next(2, 9); string questionText = string.Format("请选出是合数的数。"); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c) => { for (int j = 2; j < c / 2 + 1; j++) { if (c % j == 0) { return(true); } } return(false); })) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); int flag = 1; int j = 1; if (value == 0) { flag = 0; } for (j = 2; j < value / 2 + 1; j++) { if (value % j == 0) { flag = 2; break; } } if (flag == 0) { strBuilder.AppendLine(string.Format("0 不是合数。")); } else if (flag == 1) { strBuilder.AppendLine(string.Format("{0}只有两个约数{1},{2}。", value, 1, value)); } else { strBuilder.AppendLine(string.Format("{0}有约数{1},{2},{3}...,大于2个,是正确答案。", value, 1, value, j)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private MCQuestion CreateMCQuestion(SectionBaseInfo info, Section section) { //int minValue = 50; //int maxValue = 500; //if (info is SectionValueRangeInfo) //{ // SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; // minValue = decimal.ToInt32(rangeInfo.MinValue); // maxValue = decimal.ToInt32(rangeInfo.MaxValue); //} //if (maxValue < 100) //{ // maxValue = 100; //} //if (section.QuestionCollection.Count == 0) // this.questionValueList.Clear(); //Random rand = new Random((int)DateTime.Now.Ticks); //int valueA = 0, valueB = 0, valueC = 0, valueM = 0, valueN = 0, valueTmp = 0; //int sign = 0; //int j = 0; //while (true) //{ // valueA = rand.Next(minValue, maxValue + 1); // valueTmp = rand.Next(100, maxValue + 1); // valueM = valueTmp / 100; // valueN = rand.Next(1, 9 + 1); // sign = rand.Next(0, 2); // if (sign == 0) //正号 // { // valueB = valueM * 100 + valueN; // } // else //负号 // { // valueB = valueM * 100 - valueN; // } // valueC = valueA + valueB; // if (valueB > 0) // { // break; // } //} int valueA = 0, valueB = 0, valueC = 0, valueM = 0, valueN = 0, sign = 0; //this.GetRandomValues(info, &valueA, &valueB, &valueC, &valueM, &valueN, &sign); this.GetRandomValues(info, ref valueA, ref valueB, ref valueC, ref valueM, ref valueN, ref sign); questionValueList.Add((valueA)); string questionText = string.Format("{0}+{1}=", valueA, valueB); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int valueLst = (valueC) - 30, valueMst = (valueC) + 30; if (valueLst - 30 <= 1) { valueLst = 1; } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueLst, valueMst, false, (c => (c == valueC)), valueC)) { optionList.Add(option); } return(optionList); } ); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (value == valueC) { if (sign == 0) //正号 { strBuilder.AppendLine(string.Format( "{0}+{1}={0}+({2}×10+{3})={0}+{2}×10+{3}= {0}+{4}+{3}={5}+{3}={6},是正确答案。", valueA, valueB, valueM, valueN, valueM * 10, valueA + valueM * 10, value)); } else //负号 { strBuilder.AppendLine(string.Format( "{0}+{1}={0}+({2}×10-{3})={0}+{2}×10-{3}= {0}+{4}-{3}={5}-{3}={6},是正确答案。", valueA, valueB, valueM, valueN, valueM * 10, valueA + valueM * 10, value)); } } else { strBuilder.AppendLine(string.Format("{0}+{1}不等于{2}。", valueA, valueB, value)); } } mcQuestion.Solution.Content = strBuilder.ToString(); section.QuestionCollection.Add(mcQuestion); return(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { int minValue = 10; int maxValue = 100; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } int inMinValue = 2, inMaxValue = 2; if (minValue / 10 > inMinValue) { inMinValue = minValue / 10; } inMaxValue = maxValue / 10; Random rand = new Random((int)DateTime.Now.Ticks); int divValue = rand.Next(inMinValue, inMaxValue); string questionText = string.Format("请选出是{0}倍数的数。", divValue); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c => ((c % divValue) == 0)))) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (value % divValue == 0) { strBuilder.AppendLine(string.Format("{1}除以{0}等于{2},没有余数,是正确答案。", value, divValue, value / divValue)); } else { strBuilder.AppendLine(string.Format("{1}除以{0}等于{2},余数是{3}。", value, divValue, (int)(value) / divValue, value % divValue)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); decimal valueA = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueC = rand.Next(minValue, maxValue + 1); decimal result = valueA + valueB + valueC; string questionText = "从下面选项中选出符合方程定义的等式。"; MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); for (int i = 0; i < 3; i++) { decimal a = rand.Next(minValue, maxValue + 1); decimal b = rand.Next(minValue, maxValue + 1); decimal c = rand.Next(minValue, maxValue + 1); decimal d = rand.Next(minValue, maxValue + 1); if (d == c) { d = d == 0 ? d + 1 : d - 1; } QuestionOption option = new QuestionOption(); switch (i) { case 0: option.OptionContent.Content = string.Format("{0} + {1} = {2}", a, b, c); break; case 1: option.OptionContent.Content = string.Format("{0} - {1} = {2} + {3}", a, b, c, d); break; case 2: option.OptionContent.Content = string.Format("{0} × {1} = {2} × {3}", a, b, c, d); break; default: break; } optionList.Add(option); } QuestionOption correctOption = new QuestionOption(); correctOption.OptionContent.Content = string.Format("x + {0} = {1}", valueA, valueB); correctOption.IsCorrect = true; int correctIndex = rand.Next(100) % 4; if (correctIndex == optionList.Count) { optionList.Add(correctOption); } else { optionList.Insert(correctIndex, correctOption); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("x + {0} = {1},在这个等式中,含有未知数x。\n是符合方程的定义,是正确答案。", valueA, valueB); section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { int minValue = 10; int maxValue = 10000; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } List <int> questionValueList = new List <int>(); Random rand = new Random((int)DateTime.Now.Ticks); int valueA = 0, valueB = 0; int minRand = 0, maxRand = 0; int minValueTmp = minValue, maxValueTmp = maxValue; while (true) { if (minValueTmp / 10 >= 1) { minRand++; minValueTmp /= 10; } else { break; } } while (true) { if (maxValueTmp / 10 >= 1) { maxRand++; maxValueTmp /= 10; } else { break; } } valueB = rand.Next(minRand, maxRand + 1); valueA = (int)(System.Math.Pow(10, valueB)); questionValueList.Add(valueA); string questionText = string.Format("把1分成{0}份,请问可以用几位小数表示。", valueA); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int valueLst = valueB - 2, valueMst = valueB + 3; if (minRand - 20 <= 1) { valueLst = 1; } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueLst, valueMst, false, (c => (c == valueB)), valueB)) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (value == valueB) { strBuilder.AppendLine(string.Format("把1分成{0}份,可以用{1}位小数表示,是正确答案。", valueA, value)); } else { strBuilder.AppendLine(string.Format("把1分成{0}份,不可以用{1}位小数表示。", valueA, value)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private static void CreateMCQuestion(MCQuestion question, int index, FlowDocument flowDocument, bool showAnswer, bool showResponse, SelectableQuestionResponse response) { System.Windows.Documents.Section questionSection = new System.Windows.Documents.Section(); flowDocument.Blocks.Add(questionSection); List <int> optionIndexList = new List <int>(); if (question.RandomOption) { Random rand = new Random((int)DateTime.Now.Ticks); while (true) { int i = rand.Next(question.QuestionOptionCollection.Count * 10) % question.QuestionOptionCollection.Count; bool found = false; foreach (int temp in optionIndexList) { if (temp == i) { found = true; break; } } if (!found) { optionIndexList.Add(i); } if (optionIndexList.Count == question.QuestionOptionCollection.Count) { break; } Thread.Sleep(10); } } else { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { optionIndexList.Add(i); } } System.Windows.Documents.Paragraph questionContentBlock = CreateContentControl(question.Content, (index + 1).ToString() + ". ", null, response); Paragraph lastParagraph = questionContentBlock; if (showResponse) { if (Enumerable.Count <string>(response.OptionIdList) > 0) { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; if (option.Id == response.OptionIdList[0]) { lastParagraph.Inlines.Add(CreateText(" ( " + (char)('A' + i) + " )")); break; } } } else { lastParagraph.Inlines.Add(CreateText("( )")); } } else { lastParagraph.Inlines.Add(CreateText("( )")); } if (showAnswer) { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; if (option.IsCorrect) { lastParagraph.Inlines.Add(CreateText(" 正确答案:" + (char)('A' + i))); break; } } } questionSection.Blocks.Add(questionContentBlock); for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; questionSection.Blocks.Add(CreateContentControl(option.OptionContent, string.Format("\t{0}. ", (char)('A' + i)), null, response)); } }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); int minValue = 0; int maxValue = 10 + 1; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } string questionText = string.Format("选出是有限小数的数。"); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption temp in ObjectCreator.CreateDoubleTextOption(0, 0, minValue + 1, maxValue, "……")) { optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateDoubleTextOption(0, 0, minValue + 1, maxValue, "……")) { optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateDoubleTextOption(0, 0, minValue + 1, maxValue, "")) { temp.IsCorrect = true; optionList.Add(temp); } foreach (QuestionOption temp in ObjectCreator.CreateDoubleTextOption(minValue, maxValue + 1, minValue + 1, maxValue, "……")) { optionList.Add(temp); } return(optionList); } ); mcQuestion.RandomOption = true; section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; if (content.QuestionPartCollection[0] is QuestionTextPart) { QuestionTextPart decimalPart = content.QuestionPartCollection[0] as QuestionTextPart; if (decimalPart.Text.IndexOf("……") < 0) { strBuilder.AppendLine(string.Format("{0}是有限小数,是正确答案。", decimalPart.Text)); } } } mcQuestion.Solution.Content = strBuilder.ToString(); }
internal Question CreateQuestion(QuestionType type) { Question question = null; switch (type) { case QuestionType.MultiChoice: { MCQuestion mcQuestion = new MCQuestion(); for (int i = 0; i < 4; i++) { QuestionOption option = new QuestionOption(); option.Index = i; mcQuestion.QuestionOptionCollection.Add(option); } question = mcQuestion; } break; case QuestionType.MultiResponse: { MRQuestion mrQuestion = new MRQuestion(); for (int i = 0; i < 4; i++) { QuestionOption option = new QuestionOption(); option.Index = i; mrQuestion.QuestionOptionCollection.Add(option); } question = mrQuestion; } break; case QuestionType.Essay: { ESQuestion esQuestion = new ESQuestion(); question = esQuestion; } break; case QuestionType.TrueFalse: { TFQuestion tfQuestion = new TFQuestion(); QuestionOption optionT = new QuestionOption(); optionT.Index = 0; QuestionOption optionF = new QuestionOption(); optionF.Index = 1; tfQuestion.QuestionOptionCollection.Add(optionT); tfQuestion.QuestionOptionCollection.Add(optionF); tfQuestion.RandomOption = true; question = tfQuestion; } break; case QuestionType.Match: { MAQuestion maQuestion = new MAQuestion(); for (int i = 0; i < 4; i++) { MAQuestionOption option = new MAQuestionOption(); option.Index = i; maQuestion.OptionList.Add(option); } question = maQuestion; } break; case QuestionType.FillInBlank: { FIBQuestion fibQuestion = new FIBQuestion(); question = fibQuestion; } break; case QuestionType.Composite: { CPQuestion cpQuestion = new CPQuestion(); question = cpQuestion; } break; } question.DifficultyLevel = 3; question.CreateTime = DateTime.Now.ToUniversalTime(); question.ModifyTime = DateTime.Now.ToUniversalTime(); return(question); }
private MCQuestion CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } if (section.QuestionCollection.Count == 0) { this.questionValueList.Clear(); } Random rand = new Random((int)DateTime.Now.Ticks); int valueA = 0, valueB = 0, valueC = 0; int j = 0; int flag = 0; valueC = rand.Next(minValue / 3, maxValue / 3); while (true) { flag = 0; //for (int i2 = 0; i2 < maxValue + minValue; i2++) while (true) { valueA = rand.Next(valueC, maxValue); valueB = rand.Next(valueC, maxValue); if (valueA % valueC == 0 && valueC >= valueA / valueC && valueB % valueC == 0 && valueC >= valueB / valueC && valueA != valueB && valueC != valueA && valueC != valueB && ((valueA > valueB && valueA % valueB != 0) || (valueB > valueA && valueB % valueA != 0))) { flag = 1; break; } //int lop = 0; //if (valueA > valueB) // lop = valueB; //else // lop = valueA; //for (j = lop; j > 1; j--) //{ // if (valueA % j == 0 && valueB % j == 0) // { // flag = 1; // break; // } //} } //if (Enumerable.Where<int>(questionValueList, (c => (c == valueA))).Count<int>() > 0) //{ // Thread.Sleep(10); // continue; //} break; } questionValueList.Add(valueA); string questionText = string.Format("请找出{0}和{1}的最大公约数。", valueA, valueB); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); int valueLst = valueC - 20, valueMst = valueC + 20; if (j - 20 <= 1) { valueLst = 1; } foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, valueLst, valueMst, false, (c => (c == valueC)), valueC)) { optionList.Add(option); } return(optionList); } ); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); if (value == valueC) { strBuilder.AppendLine(string.Format( "{0}除以{1}等于{2},没有余数,并且{3}除以{4}等于{5},没有余数,{1}是最大公约数,是正确答案。", valueA, value, valueA / value, valueB, value, valueB / value)); } else { strBuilder.AppendLine(string.Format("{0}不是{1}和{2}的最大公约数。", value, valueA, valueB)); } } mcQuestion.Solution.Content = strBuilder.ToString(); section.QuestionCollection.Add(mcQuestion); return(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section) { int minValue = 10; int maxValue = 100; if (sectionInfo is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } if (section.QuestionCollection.Count == 0) { this.questionValueList.Clear(); } Random rand = new Random((int)DateTime.Now.Ticks); int valueA = 0, valueC = 0; //valueA = rand.Next(minValue, maxValue); while (true) { int sumCommonDivisor = 0; valueA = rand.Next(minValue, maxValue); //valueB = rand.Next(minValue, maxValue); //if (valueA < valueB) // valueC = valueA; //else if (valueA > valueB) // valueC = valueB; //else // continue; for (int j2 = 1; j2 < valueA; j2++) { if (valueA % j2 == 0) { sumCommonDivisor++; } } if (sumCommonDivisor >= 4) { break; } } string questionText = string.Format("请选出与{0}互质的数。", valueA); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c) => { int sumCommonDivisor = 0; if (valueA < c) { valueC = valueA; } else if (valueA > c) { valueC = decimal.ToInt32(c); } else { return(false); } for (int j2 = 1; j2 < valueC; j2++) { if (valueA % j2 == 0 && c % j2 == 0) { sumCommonDivisor++; } } if (sumCommonDivisor == 1) { return(true); } return(false); } )) { optionList.Add(option); } return(optionList); } ); section.QuestionCollection.Add(mcQuestion); StringBuilder strBuilder = new StringBuilder(); foreach (QuestionOption option in mcQuestion.QuestionOptionCollection) { QuestionContent content = option.OptionContent; decimal value = System.Convert.ToDecimal(content.Content); int sumCommonDivisor = 0; if (valueA < value) { valueC = valueA; } else { valueC = decimal.ToInt32(value); } for (int j2 = 1; j2 < valueC; j2++) { if (valueA % j2 == 0 && value % j2 == 0) { sumCommonDivisor++; } } if (sumCommonDivisor == 1) { strBuilder.AppendLine(string.Format("{0}和{1}只有公约数1,是正确答案。", valueA, value)); } else { strBuilder.AppendLine(string.Format("{0}和{1}有{2}个公约数。", valueA, value, sumCommonDivisor)); } } mcQuestion.Solution.Content = strBuilder.ToString(); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { if (section.QuestionCollection.Count == 0) { this.questionValueList.Clear(); } int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); int minValueA = 1; if (minValue > 0) { minValueA = minValue; } decimal valueA = rand.Next(minValueA, maxValue); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue); bool exist = true; for (int i = 0; i < 50; i++) { if (Enumerable.Where <decimal>(this.questionValueList, (c => (c == valueA * valueB))).Count <decimal>() == 0) { exist = false; break; } valueA = rand.Next(minValueA, maxValue); Thread.Sleep(10); valueB = rand.Next(minValue, maxValue); } if (exist) { return; } decimal result = valueA * valueB; this.questionValueList.Add(result); string questionText = string.Format("从下面选项中选出{0}除以{1}的商。", result, valueA); MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 4, minValue, maxValue, false, (c => ((c == valueB))), valueB)) { optionList.Add(option); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("被除数{0}除以除数{1}的商是{2},所以正确答案是{2}。", result, valueA, valueB); section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); // 因为因数为0比较特殊,所以暂时先排除0 if (minValue < 1) { minValue++; } decimal valueA = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue + 1); Thread.Sleep(10); decimal valueC = rand.Next(minValue, maxValue + 1); decimal result = (valueA + valueB) * valueC; string questionText = "从下面选项中选出符合乘法分配率的等式。"; MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); //for (int i = 0; i < 3; i++) //{ // decimal a = rand.Next(minValue, maxValue + 1); // decimal b = rand.Next(minValue, maxValue + 1); // decimal c = rand.Next(minValue, maxValue + 1); // decimal d = rand.Next(minValue, maxValue + 1); // if (d == c) // { // d = d == 0 ? d + 1 : d - 1; // } // QuestionOption option = new QuestionOption(); // option.OptionContent.Content = string.Format("({0} × {1}) × {2} = {0} × ({1} × {3})", a, b, c, d); // optionList.Add(option); //} QuestionOption option1 = new QuestionOption(); option1.OptionContent.Content = string.Format("({0} + {1}) × {2} = {0} + {1} × {2}", valueA, valueB, valueC); optionList.Add(option1); QuestionOption option2 = new QuestionOption(); option2.OptionContent.Content = string.Format("({0} + {1}) × {2} = {0} × {2} + {1}", valueA, valueB, valueC); optionList.Add(option2); QuestionOption option3 = new QuestionOption(); option3.OptionContent.Content = string.Format("({0} + {1}) × {2} = ({0} + {2}) × ({1} + {2})", valueA, valueB, valueC); optionList.Add(option3); QuestionOption correctOption = new QuestionOption(); correctOption.OptionContent.Content = string.Format("({0} + {1}) × {2} = {0} × {2} + {1} × {2}", valueA, valueB, valueC); correctOption.IsCorrect = true; int correctIndex = rand.Next(100) % 4; if (correctIndex == optionList.Count) { optionList.Add(correctOption); } else { optionList.Insert(correctIndex, correctOption); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("({0} + {1}) × {2} = {0} × {2} + {1} × {2},在这个等式中,两边结果不变,都是{3}。\n是符合乘法分配率的,是正确答案。", valueA, valueB, valueC, result); section.QuestionCollection.Add(mcQuestion); }
private void CreateMCQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); if (minValue < 1) { minValue = 1; } decimal valueC = rand.Next(minValue, maxValue / 2 + 1); Thread.Sleep(10); decimal valueB = rand.Next(minValue, maxValue - decimal.ToInt32(valueC) + 1); Thread.Sleep(10); decimal valueA = rand.Next(decimal.ToInt32(valueB + valueC), maxValue + 1); decimal result = valueA - valueB - valueC; string questionText = "从下面选项中选出符合减法的性质的等式。"; MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); for (int i = 0; i < 2; i++) { decimal a = rand.Next(minValue, maxValue + 1); decimal b = rand.Next(minValue, maxValue + 1); decimal c = rand.Next(minValue, maxValue + 1); decimal d = rand.Next(minValue, maxValue + 1); if (d == c) { d = d == 0 ? d + 1 : d - 1; } QuestionOption option = new QuestionOption(); option.OptionContent.Content = string.Format("{0} - {1} - {2} = {0} - ({1} + {3})", a, b, c, d); optionList.Add(option); } QuestionOption option2 = new QuestionOption(); option2.OptionContent.Content = string.Format("{0} - {1} - {2} = {0} - ({1} - {2})", valueA, valueB, valueC); optionList.Add(option2); QuestionOption correctOption = new QuestionOption(); correctOption.OptionContent.Content = string.Format("{0} - {1} - {2} = {0} - ({1} + {2})", valueA, valueB, valueC); correctOption.IsCorrect = true; int correctIndex = rand.Next(100) % 4; if (correctIndex == optionList.Count) { optionList.Add(correctOption); } else { optionList.Insert(correctIndex, correctOption); } return(optionList); } ); mcQuestion.Solution.Content = string.Format("{0} - {1} - {2} = {0} - ({1} + {2}),在这个等式中,两边结果一样,都是{3}。\n是符合减法的性质的,是正确答案。", valueA, valueB, valueC, result); section.QuestionCollection.Add(mcQuestion); }
/// <summary> /// Parse Xml document and generate questions /// </summary> private void parseXmlDocument() { XmlDocument doc = LoadDocumentWithSchemaValidation(); if (doc == null) { return; } XmlNodeList quiz_list = doc.SelectNodes("/quiz/question"); foreach (XmlNode question_node in quiz_list) { TealUnity.Question question; string type = question_node.Attributes["type"].Value; string title = question_node["title"].InnerText; string text = question_node["text"].InnerText; switch (type) { case "input-number": { question = new InputQuestion <float>(title, text); float answer = 0; try { answer = float.Parse(question_node["answer"].InnerText); } catch (FormatException e) { Debug.LogError(e.Message); } ((InputQuestion <float>)question).setAnswer(answer); break; } case "input-text": { question = new InputQuestion <string>(title, text); string answer = question_node["answer"].InnerText; ((InputQuestion <string>)question).setAnswer(answer); break; } case "multiple-choice": { question = new MCQuestion(title, text); XmlNodeList answerchoice_list = question_node.SelectNodes("answerchoice"); int i = 0; foreach (XmlNode anserchoice_node in answerchoice_list) { bool correct = bool.Parse(anserchoice_node.Attributes["correct"].Value); string answer_text = anserchoice_node["text"].InnerText; AnswerChoice answerchoice = new AnswerChoice(answer_text, correct); if (anserchoice_node["image"] != null) { answerchoice.setImagePath(anserchoice_node["image"].InnerText); } ((MCQuestion)question).setAnswerChoise(answerchoice, i); i++; } break; } default: continue; } if (question_node["image"] != null) { question.setImagePath(question_node["image"].InnerText); } questions.Add(question); } }