예제 #1
0
        public static AnswerList pickAnswers(string answersNumbers, AnswerList availableAnswers)
        {
            char tempChar;

            char[]     spearator     = { ' ' };
            string[]   result        = answersNumbers.Split(spearator);
            AnswerList chosenAnswers = new AnswerList();

            if (result.Length != 0)
            {
                foreach (var item in result)
                {
                    if (item != "" && char.TryParse(item, out tempChar))
                    {
                        for (int i = 0; i < availableAnswers.Count(); i++)
                        {
                            if (tempChar == availableAnswers[i].questionNumber)
                            {
                                chosenAnswers.Add(availableAnswers[i]);
                            }
                        }
                    }
                }
            }
            if (chosenAnswers.Count() != 0)
            {
                return(chosenAnswers);
            }
            return(null);
        }
예제 #2
0
        public bool correct(object object1)
        {
            AnswerList ans             = object1 as AnswerList;
            int        numberOfAnswers = 0;

            if (ans != null)
            {
                if (ans.Count() != this.Count())
                {
                    return(false);
                }
                else if (ans.Count() == this.Count())
                {
                    for (int i = 0; i < ans.Count(); i++)
                    {
                        for (int j = 0; j < this.Count(); j++)
                        {
                            if (ans[i].questionNumber == this[j].questionNumber)
                            {
                                numberOfAnswers++;
                            }
                        }
                    }
                    if (numberOfAnswers == this.Count())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
예제 #3
0
 public static Answer pickAnswer(char questionNumber, AnswerList availableAnswers)
 {
     for (int i = 0; i < availableAnswers.Count; i++)
     {
         if (availableAnswers[i].questionNumber == questionNumber)
         {
             return(availableAnswers[i]);
         }
     }
     return(null);
 }
예제 #4
0
        static void Main(string[] args)
        {
            //char[] spearator = {' '};
            //string str = "a b c d";
            //string[] result = str.Split(spearator);
            //foreach (var item in result)
            //{
            //    Console.WriteLine(char.Parse(item));
            //}


            AnswerList lst = new AnswerList()
            {
                new Answer('a', "True"), new Answer('b', "false"), new Answer('c', "maybe")
            };
            //AnswerList lst2 = new AnswerList() { new Answer('c', "True"), new Answer('b', "false") };
            //Answer ans = new Answer('a' , "YES");
            //foreach (var item in AnswerList.pickAnswers("a b" , lst))
            //{
            //Console.WriteLine(/*lst2.correct(AnswerList.pickAnswers("c b", lst))*/ ans.correct(new Answer('a',"YESsss")));
            //}
            ExamParent exam = new PracticeExam();

            exam.questionAnswerDictionary = new Dictionary <Question, AnswerList>();
            exam.questionAnswerDictionary.Add(new TrueOrFalse("True or false", "Is the sky blue?", 2, new Answer('a', "True")), lst);
            foreach (var item in exam.questionAnswerDictionary)
            {
                Console.WriteLine($"{item.Key.head}");
                Console.WriteLine($"{item.Key.body}");
                Console.WriteLine($"marks : {item.Key.mark}");
                foreach (var item2 in item.Value)
                {
                    Console.WriteLine(item2.questionNumber + ")" + item2.answerBody);
                }
                if (item.Key.correctAnswer.correct(AnswerList.pickAnswer(Console.ReadKey().KeyChar, item.Value)))
                {
                    exam.totalMarks = exam.totalMarks + item.Key.mark;
                }
            }
            Console.WriteLine("\n" + "total user marks " + exam.totalMarks);
            Console.ReadKey();
        }