Question
So this is my project and I cannot figure out why it when I run it, it pulls up file manager and I have to
So this is my project and I cannot figure out why it when I run it, it pulls up file manager and I have to choose the folder it goes to then. Heres what it is:
Create a program that: 1. Creates an array of either character or string that stores the correct answers (5 points). The array only has the letter, not the question number. Remember the array index starts at 0. 2. Create a text file called Response.txt that is a simulation of a student answering the questions (5 points). Only write the letter answer and only one letter per line. Remember your file must have 20 lines of answers from A, B, C or D. See following example A C B D C 3. Your program should read the text file and store the answers in an array (10 points). 4. After the students answers are read from the file and stored in the array, the program should compare the array with correct answers and the array with the students answer and determine how many answers are correct and how many are incorrect (20 points). 5. The program should display a message indicating whether the student passed or failed the project (5 points). Passing grade is 14 correct answers. 6. The program should then display the total number of correct answers, the total number of incorrect answers, and a list showing the question numbers of the incorrectly answered questions (55 points).
using System; using System.Windows.Forms; using System.IO;
namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] CorrectAns = new string[] {"B", "D", "A", "A", "C", "A", "B", "B", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};
private void Form1_Load(object sender, EventArgs e) {
}
private void Button1_Click(object sender, EventArgs e) { #pragma warning disable IDE0017 // Simplify object initialization OpenFileDialog theDialog = new OpenFileDialog(); #pragma warning restore IDE0017 // Simplify object initialization theDialog.Title = "Open Text File"; theDialog.Filter = "TXT files|*.txt"; theDialog.InitialDirectory = @"C:\"; int correctAnsCount = 0; int IncorrectAns = 0; string missedQuestion = ""; if (theDialog.ShowDialog() == DialogResult.OK) { try { Stream myStream = null; if ((myStream = theDialog.OpenFile()) != null) {
using (myStream) {
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Tyler\source epos\WindowsFormsApp3\WindowsFormsApp3\Response.txt"); for (int i = 0; i < CorrectAns.Length; i++) { if (CorrectAns[i].ToString() == lines[i].ToString()) { correctAnsCount++; } else if (lines[i].ToString() == " ") { missedQuestion += i.ToString() + ","; } else { IncorrectAns++; }
} } } int PassorFail = correctAnsCount * 100 / 20; if (PassorFail > 60) { textBox1.Text = "Pass"; } else { textBox1.Text = "Fail"; } textBox2.Text = correctAnsCount.ToString(); textBox3.Text = IncorrectAns.ToString(); textBox4.Text = missedQuestion.TrimEnd(',');
} catch (Exception ex) { MessageBox.Show("Error: Could not read file: " + ex.Message); } } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started