コード例 #1
0
        //import questions
        public static void ImportQuestions()
        {
            MakeHead("Import Questions");

            Console.WriteLine("Enter the location of the file to read from:");
            string filename = Console.ReadLine();

            if (File.Exists(filename))
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    //clear questions list
                    Questions.Clear();

                    //read all text
                    string allText = sr.ReadToEnd();

                    //split text into questions
                    string[] fullQuestions = allText.Split('-');

                    //for each question from file
                    foreach (string fullQuestion in fullQuestions)
                    {
                        //getting rid of useless white space characters and cutting-off each string
                        string[] q = fullQuestion.Trim().Split('\n');

                        //the first string is the question
                        string question = q[0].Substring(3);//Substring to cut-off letter and space (A. , B. , etc.)
                        string choise1  = q[1].Substring(3);
                        string choise2  = q[2].Substring(3);
                        string choise3  = q[3].Substring(3);
                        string choise4  = q[4].Substring(3);
                        CorrectChoise.TryParse(q[5], true, out CorrectChoise cc);//don't forget to enter correct choise into file :)

                        //putting all question data into the new question and adding it into the list
                        var newQuestion = new MultipleChoiceQuestion(question, choise1, choise2, choise3, choise4, cc);
                        Questions.Add(newQuestion);
                    }
                }
            }
            else
            {
                Console.WriteLine($"Could not find a part of the path '{filename}'");
            }

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
            Console.Clear();
        }
コード例 #2
0
        //create new question
        public static void CreateNewQuestion()
        {
            MakeHead("New Question");

            Console.WriteLine($"There are {Questions.Count} questions in the exam.\n");

            Console.WriteLine("Enter the question:");
            string newQ = Console.ReadLine();

            Console.WriteLine("Enter choice 1 for the question:");
            string newC1 = Console.ReadLine();

            Console.WriteLine("Enter choice 2 for the question:");
            string newC2 = Console.ReadLine();

            Console.WriteLine("Enter choice 3 for the question:");
            string newC3 = Console.ReadLine();

            Console.WriteLine("Enter choice 4 for the question:");
            string newC4 = Console.ReadLine();

            Console.WriteLine("Enter the correct choice (A, B, C, D):");
            //check if user's input is in correct form (A,B,C,D)
Parse:
            if (!CorrectChoise.TryParse(Console.ReadLine(), true, out CorrectChoise cc))
            {
                //if input not in correct form
                Console.WriteLine("Write A, B, C or D");
                goto Parse;
            }

            //create new question object and putting all usser's inputs inside it
            MultipleChoiceQuestion newQuestion = new MultipleChoiceQuestion(newQ, newC1, newC2, newC3, newC4, cc);

            Questions.Add(newQuestion);


            Console.WriteLine($"Successfully added question {Questions.Count} to exam.\n" +
                              "Press any key to continue.");
            Console.ReadKey();
            Console.Clear();
        }