private void CreateTableQuestion(SectionBaseInfo sectionInfo, Section section) { // Table Question Random rand = new Random((int)DateTime.Now.Ticks); int divValue = 2;// i; string questionText = string.Format("请下表中选出是奇数的数。"); TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((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( 36, minValue, maxValue, true, (c => ((c % divValue) != 0)))) { optionList.Add(option); } return(optionList); }); tableQuestion.Solution.Content = this.CreateSolution(divValue); section.QuestionCollection.Add(tableQuestion); }
private void CreateTableQuestion(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); decimal result = rand.Next(minValue, maxValue); bool exist = true; for (int i = 0; i < 50; i++) { if (Enumerable.Where <decimal>(this.questionValueList, (c => (c == result))).Count <decimal>() == 0) { exist = false; break; } Thread.Sleep(10); result = rand.Next(minValue, maxValue); } if (exist) { return; } this.questionValueList.Add(result); string questionText = string.Format("从下面选项中选出两个数的商是{0}", result); TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); for (int j = 0; j < 36; j++) { if (rand.Next() % 2 == 0) // Create correct Option { int tmpvalue = 1; if (minValue > 0) { tmpvalue = minValue; } decimal valueB = rand.Next(tmpvalue, maxValue); decimal valueA = result * valueB; QuestionOption option = new QuestionOption(); option.IsCorrect = true; option.OptionContent.Content = string.Format("{0} ÷ {1}", valueA, valueB); optionList.Add(option); } else { int tmpvalue = 1; if (minValue > 0) { tmpvalue = minValue; } decimal valueB = rand.Next(tmpvalue, maxValue); decimal valueA = rand.Next(minValue, maxValue); QuestionOption option = new QuestionOption(); option.IsCorrect = (valueA / valueB == result) ? true : false; option.OptionContent.Content = string.Format("{0} ÷ {1}", valueA, valueB); optionList.Add(option); } } return(optionList); } ); // tableQuestion.Solution.Content = string.Format("加数{0}与加数{1}的和是{2},所以正确答案是{2}。", valueA, valueB, result); section.QuestionCollection.Add(tableQuestion); }
private void CreateTableQuestion(SectionBaseInfo sectionInfo, Section section) { Random rand = new Random((int)DateTime.Now.Ticks); string questionText = string.Format("请下表中选出是合数的数。"); StringBuilder strBuilder = new StringBuilder(); TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((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( 36, minValue, maxValue, true, (c) => { for (int j = 2; j < c / 2 + 1; j++) { if (c % j == 0) { return(true); } } return(false); })) { optionList.Add(option); decimal optionValue = Convert.ToDecimal(option.OptionContent.Content); if (optionValue == 0) { strBuilder.AppendLine(string.Format("0 不是合数。")); } else if (!option.IsCorrect) { strBuilder.AppendLine(string.Format("{0}只有两个约数{1},{2}。", optionValue, 1, optionValue)); } else { decimal thirdValue = 0; for (int j = 2; j < optionValue / 2 + 1; j++) { if (optionValue % j == 0) { thirdValue = j; break; } } strBuilder.AppendLine(string.Format("{0}有约数{1},{2},{3}...,大于2个,是正确答案。", optionValue, 1, optionValue, thirdValue)); } } return(optionList); }); tableQuestion.Solution.Content = strBuilder.ToString(); tableQuestion.Tip = "合数至少有3个约数。"; section.QuestionCollection.Add(tableQuestion); }
private void CreateTableQuestion(SectionBaseInfo sectionInfo, Section section) { // Table Question Random rand = new Random((int)DateTime.Now.Ticks); string questionText = string.Format("请下表中选出至少有两个质因数的数。"); TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((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( 36, minValue, maxValue, true, (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); }); tableQuestion.Tip = this.CreateTip(); section.QuestionCollection.Add(tableQuestion); }
private static Paragraph CreateTableQuestion(TableQuestion question, int index, FlowDocument flowDocument, bool showAnswer, bool showResponse, SelectableQuestionResponse response) { Paragraph questionPara = new Paragraph(); flowDocument.Blocks.Add(questionPara); Run questionBodyRun = new Run((index + 1).ToString() + ". " + question.Content.Content + "\n"); questionPara.Inlines.Add(questionBodyRun); Table optionTable = new Table(); TableRowGroup tableRowGroup = new TableRowGroup(); optionTable.RowGroups.Add(tableRowGroup); flowDocument.Blocks.Add(optionTable); int i = 0; int rowCount = (int)System.Math.Sqrt(question.QuestionOptionCollection.Count); for (int row = 0; row < rowCount; row++) { tableRowGroup.Rows.Add(new TableRow()); TableRow tableRow = tableRowGroup.Rows[row]; for (int col = 0; col < rowCount; col++) { QuestionOption option = question.QuestionOptionCollection[i++]; System.Windows.Documents.Section optionPara = CreateContentControl(option.OptionContent, string.Empty, null, response); if (showResponse) { if (Enumerable.Count <string>(Enumerable.Where <string>(response.OptionIdList, (c => (c == option.Id)))) > 0) { optionPara.FontWeight = FontWeights.Bold; optionPara.FontSize = 16f; optionPara.FontStyle = FontStyles.Italic; } } TableCell cell = new TableCell(optionPara); cell.BorderThickness = new Thickness(1); cell.BorderBrush = new SolidColorBrush(Colors.Black); cell.TextAlignment = TextAlignment.Center; cell.LineHeight = 30f; tableRow.Cells.Add(cell); } } if (showAnswer) { System.Windows.Documents.Section answerSection = new System.Windows.Documents.Section(); Paragraph answerPara = new Paragraph(); answerSection.Blocks.Add(answerPara); flowDocument.Blocks.Add(answerSection); answerPara.Inlines.Add("答案:"); foreach (QuestionOption option in question.QuestionOptionCollection) { if (option.IsCorrect) { CreateContentControl(option.OptionContent, " ", answerSection, response); answerPara.Inlines.Add(", "); } } } return(questionPara); }
private void CreateTableQuestion(SectionBaseInfo info, Section section) { int minValue = 10; int maxValue = 100; if (info is SectionValueRangeInfo) { SectionValueRangeInfo rangeInfo = info as SectionValueRangeInfo; minValue = decimal.ToInt32(rangeInfo.MinValue); if (minValue < 1) { minValue = 1; } maxValue = decimal.ToInt32(rangeInfo.MaxValue); } Random rand = new Random((int)DateTime.Now.Ticks); string questionText = "从表格中选择符合乘法分配率条件的等式"; TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); for (int j = 0; j < 36; j++) { if (rand.Next() % 2 == 0) // Create correct Option { decimal valueA = rand.Next(minValue, maxValue + 1); decimal valueB = rand.Next(minValue, maxValue + 1); decimal valueC = rand.Next(minValue, maxValue + 1); QuestionOption option = new QuestionOption(); option.IsCorrect = true; option.OptionContent.Content = string.Format("({0}+{1})×{2}={0}×{2}+{1}×{2}", valueA, valueB, valueC); optionList.Add(option); } else { decimal valueA = rand.Next(minValue, maxValue + 1); decimal valueB = rand.Next(minValue, maxValue + 1); decimal valueC = rand.Next(minValue, maxValue + 1); decimal valueD = rand.Next(minValue, maxValue + 1); QuestionOption option = new QuestionOption(); option.IsCorrect = (valueC == valueD) ? true : false; option.OptionContent.Content = string.Format("({0}+{1})×{2}={0}×{2}+{1}×{3}", valueA, valueB, valueC, valueD); optionList.Add(option); } } return(optionList); } ); // tableQuestion.Solution.Content = string.Format("加数{0}与加数{1}的和是{2},所以正确答案是{2}。", valueA, valueB, result); section.QuestionCollection.Add(tableQuestion); }
private void CreateTableQuestion(SectionBaseInfo sectionInfo, Section section) { // Table Question Section sectionTable = ObjectCreator.CreateSection(sectionInfo.Name, sectionInfo.Description); 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 valueA = rand.Next(minValue, maxValue); string questionText = string.Format("请在下表中选出与{0}互质的数。", valueA); TableQuestion tableQuestion = ObjectCreator.CreateTableQuestion((content) => { content.Content = questionText; content.ContentType = ContentType.Text; return; }, () => { List <QuestionOption> optionList = new List <QuestionOption>(); foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions( 36, minValue, maxValue, true, (c) => { int sumCommonDivisor = 0; int valueC; 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); }); tableQuestion.Tip = this.CreateTip(); section.QuestionCollection.Add(tableQuestion); }
public static Question CreateSubQuestion(String line) { Question temp = new OneChoice(Constants.MathCourse, 1, Constants.OneChoiceQuestionType, String.Empty, String.Empty); String[] properties = line.Split(Constants.SemiColon); char course = Convert.ToChar(properties[0]); int difficulty = Convert.ToInt32(properties[1]); char questionType = Convert.ToChar(properties[2]); String question = properties[3]; switch (questionType) { case Constants.OneChoiceQuestionType: temp = new OneChoice(course, difficulty, questionType, question, properties[4]); break; case Constants.MultipleChoiceQuestionType: String[] possibleAnswers = new String[5]; bool[] correctAnswers = new bool[5]; for (int i = 0; i <= 4; i++) { possibleAnswers[i] = properties[i + 4]; correctAnswers[i] = Convert.ToBoolean(properties[i + 9]); } temp = new MultipleChoice(course, difficulty, questionType, question, possibleAnswers, correctAnswers); break; case Constants.DragDropQuestionType: String[] dragAnswers = new String[5]; String[] dropAnswers = new String[5]; for (int i = 0; i <= 4; i++) { dragAnswers[i] = properties[i + 4]; dropAnswers[i] = properties[i + 9]; } temp = new DragNDrop(course, difficulty, questionType, question, dragAnswers, dropAnswers); break; case Constants.TableQuestionType: temp = new TableQuestion(course, difficulty, questionType, question, Convert.ToInt32(properties[4])); break; } return temp; }
private void QuestionActivityTappedMethod(TableQuestion question) { NavHelper.NavToQuestionPage(question.Id, this.Frame); SystemNavigationManager.GetForCurrentView().BackRequested -= QuestionPage_BackRequested; }