//start exam public static void StartExam() { //delete all answers from Answers list from previous try Answers.Clear(); //number of the question int i = 0; foreach (var question in Questions) { i++; Console.WriteLine($"Question {i}\n" + "-----------------\n" + $"{question.Question}\n" + $"A. {question.Choise1}\n" + $"B. {question.Choise2}\n" + $"C. {question.Choise3}\n" + $"D. {question.Choise4}\n"); Console.WriteLine("Your answer (A,B,C,D)"); //check if the input is in correct form Input: if (!CorrectChoise.TryParse(Console.ReadLine(), true, out CorrectChoise cc)) { //if input not in correct form Console.WriteLine("Write A, B, C or D"); goto Input; } //adding user's answer to Answers list Answers.Add(cc); Console.Clear(); } }
public MultipleChoiceQuestion(string q, string c1, string c2, string c3, string c4, CorrectChoise cc) { Question = q; Choise1 = c1; Choise2 = c2; Choise3 = c3; Choise4 = c4; CorrectChoise = cc; }
//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(); }
//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(); }
//edit question public static void EditQuestion() { MakeHead("Edit Question"); Console.WriteLine("Enter the question number to edit:"); //check if user's input is integer Input: if (!int.TryParse(Console.ReadLine(), out int i)) { //if user inputs not integer Console.WriteLine("Write a number"); goto Input; } //check if there is the user inputted index in the questions list if (i - 1 < Questions.Count) { var q = Questions[i - 1]; Console.WriteLine("The question is as follows:\n" + $"Question {i}\n" + "-----------------\n" + $"{q.Question}\n" + $"A. {q.Choise1}\n" + $"B. {q.Choise2}\n" + $"C. {q.Choise3}\n" + $"D. {q.Choise4}"); Console.WriteLine(); Console.WriteLine("Enter the question:"); q.Question = Console.ReadLine(); Console.WriteLine("Enter choice 1 for the question:"); q.Choise1 = Console.ReadLine(); Console.WriteLine("Enter choice 2 for the question:"); q.Choise2 = Console.ReadLine(); Console.WriteLine("Enter choice 3 for the question:"); q.Choise3 = Console.ReadLine(); Console.WriteLine("Enter choice 4 for the question:"); q.Choise4 = Console.ReadLine(); Console.WriteLine("Enter the correct choice (A, B, C, D):"); //check if user's input is in correct form Choice: if (!CorrectChoise.TryParse(Console.ReadLine(), true, out CorrectChoise cc)) { //if user's input not in correct form Console.WriteLine("Only A, B, C or D allowed"); goto Choice; } Console.WriteLine($"Successfully updated question {i}"); } else { Console.WriteLine($"Error! {i} is not a valid question number."); } Console.WriteLine("Press any key to continue."); Console.ReadKey(); Console.Clear(); }