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 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); }
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) { 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 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) => { for (int j = 2; j < c / 2 + 1; j++) { if (c % j == 0) { return(false); } } return(true); })) { 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 = 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); } 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 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)); } } }