Example #1
0
        protected virtual SoonLearning.Math.Data.Section CreateSection(SectionBaseInfo info, BackgroundWorker worker)
        {
            SoonLearning.Math.Data.Section section = ObjectCreator.CreateSection(info.Name, info.Description);

            Random rand           = new Random((int)DateTime.Now.Ticks);
            int    generatedCount = 0;

            while (true)
            {
                if (generatedCount == info.QuestionCount)
                {
                    break;
                }

                try
                {
                    AppendQuestion(info, section);
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }

                worker.ReportProgress(0, null);
                Debug.WriteLine(generatedCount);

                generatedCount++;

                Thread.Sleep(50);
            }

            return(section);
        }
Example #2
0
        private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section secton)
        {
            Section sectionMC = ObjectCreator.CreateSection(sectionInfo.Name, sectionInfo.Description);

            Random rand = new Random((int)DateTime.Now.Ticks);

            int    divValue     = rand.Next(2, 13);
            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>();
                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 => ((c % divValue) == 0))))
                {
                    optionList.Add(option);
                }

                return(optionList);
            }
                                                                   );

            secton.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("{0}除以{1}等于{2},没有余数,是正确答案。", value, divValue, value / divValue));
                }
                else
                {
                    strBuilder.AppendLine(string.Format("{0}除以{1}等于{2},余数是{3}。", value, divValue, (int)(value) / divValue, value % divValue));
                }
            }
            mcQuestion.Solution.Content = strBuilder.ToString();
        }
        private Section CreateTableSection(SectionBaseInfo sectionInfo, BackgroundWorker worker)
        {
            // Table Question
            Section sectionTable = ObjectCreator.CreateSection(sectionInfo.Name, sectionInfo.Description);

            Random rand = new Random((int)DateTime.Now.Ticks);

            for (int i = 2; i < sectionInfo.QuestionCount + 2; i++)
            {
                int    divValue     = i;
                string questionText = string.Format("请下表中选出能被{0}公倍数的数。", divValue);

                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);

                sectionTable.QuestionCollection.Add(tableQuestion);

                worker.ReportProgress(0, tableQuestion);
            }

            return(sectionTable);
        }
        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);
        }