private void loadFile() { _questions = new List <QuestionInfo>();//New paper.... if (!File.Exists("QuestionBank.txt")) { return; } StreamReader reader = new StreamReader("QuestionBank.txt"); do { string line = reader.ReadLine(); string[] data = line.Split(','); QuestionInfo info = new QuestionInfo(); info.QuestionNo = int.Parse(data[0]); info.Subject = data[1]; info.Question = data[2]; string[] choices = new string[4]; for (int i = 3; i < 7; i++) { choices[i - 3] = data[i]; } info.Choices = choices; info.CorrectAnswer = data[7]; _questions.Add(info); } while (!reader.EndOfStream); reader.Close(); }
private static bool processMenu(string choice) { switch (choice.ToUpper()) { default: return(false); case "N": QuestionInfo question = createQuestion(); qp.AddNewQuestion(question); return(true); case "U": return(true); case "F": string subject = UIComponent.GetString("Enter the Subject to find the Questions"); var questions = qp.FindQuestions(subject); foreach (QuestionInfo info in questions) { displayQuestion(info); } return(true); } }
private static void displayQuestion(QuestionInfo question) { Console.WriteLine($"Question No: {question.QuestionNo}"); Console.WriteLine($"Subject: {question.Subject}"); Console.WriteLine($"Question: {question.Question}"); Console.WriteLine($"A: {question.Choices[0]}"); Console.WriteLine($"B: {question.Choices[1]}"); Console.WriteLine($"C: {question.Choices[2]}"); Console.WriteLine($"D: {question.Choices[3]}"); Console.WriteLine($"Right Answer: {question.CorrectAnswer}"); }
public void AddNewQuestion(QuestionInfo question) { if (question != null) { _questions.Add(question);//Adds the item to the bottom of the list... saveFile(); } else { //Throw an exception.... } }
public void UpdateQuestion(QuestionInfo question) { //Iterate thro the master list and find the question based on id.. for (int i = 0; i < _questions.Count; i++) { if (_questions[i].QuestionNo == question.QuestionNo) { //Set the new details to the found QUestion _questions[i].Question = question.Question; _questions[i].Choices = question.Choices; _questions[i].CorrectAnswer = question.CorrectAnswer; _questions[i].Subject = question.Subject; return;//exit the function... } } }
private static QuestionInfo createQuestion() { QuestionInfo info = new QuestionInfo(); info.QuestionNo = UIComponent.GetInt("Enter the Question No:"); info.Subject = UIComponent.GetString("Enter the Subject"); info.Question = UIComponent.GetString("Enter the Question"); string[] choices = new string[4]; for (int i = 0; i < 4; i++) { choices[i] = UIComponent.GetString($"Enter the Choice{i+1}"); } info.Choices = choices; info.CorrectAnswer = UIComponent.GetString("Enter the Right Choice as A, B, C or D"); return(info); }