Beispiel #1
0
        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 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 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 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);
        }
Beispiel #5
0
        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));
                }
            }
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        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);
        }