Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Driver’s License Exam The local driver’s license office has asked you to create

ID: 3691821 • Letter: D

Question

Driver’s License Exam   The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the correct answers:
Figure 7-44   The Sales.txt file        
1. B      2. D      3. A      4. A      5. C     6. A      7. B      8. A      9. C     10. D    11. B     12. C     13. D     14. A     15. D    16. C     17. C     18. B     19. D     20. A  
Your program should store these correct answers in an array. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.   ONLY IN C# PLEASE.

Explanation / Answer

program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Problem2
{
    static class Program
    {
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Problem2
{
    public partial class Form1 : Form
    {
      
        string[,] bmvTest = new string[20,2];
        string[,] studentAnswers = new string[20, 2];
        int[] gradeResults = new int[22];

        public Form1()
        {
            InitializeComponent();
            ReadAnswerSheet(ref bmvTest);
            ReadStudentAnswers(ref studentAnswers);
            GradeTest(bmvTest, studentAnswers, gradeResults);
        }
        private void ReadStudentAnswers(ref string[,] studentAnswerList)
        {
            int row = 0;
            try
            {
                StreamReader inputFile = File.OpenText("StudentAnswers.txt");
              
                while (!inputFile.EndOfStream)
                {
                    string line;
                    string[] splitArray;
                  
                    //answerList.Add(int.Parse(inputFile.ReadLine()));
                    line = inputFile.ReadLine();
                    splitArray = line.Split('.');
                    studentAnswerList[row, 0] = splitArray[0];
                    studentAnswerList[row, 1] = splitArray[1];
                    rtbStudentAnswers.AppendText(studentAnswerList[row, 0] + "   " + studentAnswerList[row, 1] + " ");
                    row++;
                    //MessageBox.Show(splitArray[0] + " " + splitArray[1]);
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void ReadAnswerSheet(ref string[,] answerList)
        {
            int row = 0;
            try
            {
                StreamReader inputFile = File.OpenText("Answers.txt");
                while (!inputFile.EndOfStream)
                {
                    string line;
                    string[] splitArray;
                  
                    //answerList.Add(int.Parse(inputFile.ReadLine()));
                    line = inputFile.ReadLine();
                    splitArray = line.Split('.');
                    answerList[row, 0] = splitArray[0];
                    answerList[row, 1] = splitArray[1];
                    rtbAnswers.AppendText(answerList[row, 0] + "   " + answerList[row, 1] + " ");
                    row++;
                }
              
              
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void GradeTest(string[,] answerList,string[,] studentAnswerList,int[] resultSet)
        {
            int numCorrect = 0;
          
            for (int i = 0; i < 20; i++ )
            {
                string compare = studentAnswerList[i, 1].ToString();

                if (answerList[i,1] == compare)
                {
                    resultSet[i] = 1;
                    rtbGraded.AppendText(i + 1 + " Correct ");
                    numCorrect++;
                }
                else
                {
                    resultSet[i] = 0;
                    rtbGraded.AppendText(i + 1 + " Incorrect ");
                }
            }
          
            rtbGraded.AppendText(" " + numCorrect + " Correct Answers of 20 questions");
            if (numCorrect > 14)
            {
                lblResult.Text = "PASS";
            }
            else
            {
                lblResult.Text = "FAIL";
            }
        }
        // Buttons used for testing.
        private void button1_Click(object sender, EventArgs e)
        {
            ReadAnswerSheet(ref bmvTest);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ReadStudentAnswers(ref studentAnswers);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            GradeTest(bmvTest, studentAnswers, gradeResults);

        }
    }
}

Form1.Designer.cs

namespace DrewMazakLab1Problem2
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.rtbAnswers = new System.Windows.Forms.RichTextBox();
            this.button2 = new System.Windows.Forms.Button();
            this.rtbStudentAnswers = new System.Windows.Forms.RichTextBox();
            this.rtbGraded = new System.Windows.Forms.RichTextBox();
            this.button3 = new System.Windows.Forms.Button();
            this.lblResult = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(12, 36);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(127, 38);
            this.button1.TabIndex = 0;
            this.button1.Text = "Read in Answers";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Visible = false;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // rtbAnswers
            //
            this.rtbAnswers.Location = new System.Drawing.Point(12, 81);
            this.rtbAnswers.Name = "rtbAnswers";
            this.rtbAnswers.Size = new System.Drawing.Size(127, 356);
            this.rtbAnswers.TabIndex = 1;
            this.rtbAnswers.Text = "";
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(165, 36);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(110, 38);
            this.button2.TabIndex = 2;
            this.button2.Text = "Read in Answers to Grade";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Visible = false;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // rtbStudentAnswers
            //
            this.rtbStudentAnswers.Location = new System.Drawing.Point(165, 81);
            this.rtbStudentAnswers.Name = "rtbStudentAnswers";
            this.rtbStudentAnswers.Size = new System.Drawing.Size(110, 356);
            this.rtbStudentAnswers.TabIndex = 3;
            this.rtbStudentAnswers.Text = "";
            //
            // rtbGraded
            //
            this.rtbGraded.Location = new System.Drawing.Point(298, 81);
            this.rtbGraded.Name = "rtbGraded";
            this.rtbGraded.Size = new System.Drawing.Size(117, 356);
            this.rtbGraded.TabIndex = 4;
            this.rtbGraded.Text = "";
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(298, 36);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(102, 38);
            this.button3.TabIndex = 5;
            this.button3.Text = "Grade";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Visible = false;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // lblResult
            //
            this.lblResult.AutoSize = true;
            this.lblResult.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblResult.Location = new System.Drawing.Point(443, 220);
            this.lblResult.Name = "lblResult";
            this.lblResult.Size = new System.Drawing.Size(0, 37);
            this.lblResult.TabIndex = 6;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(42, 13);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(73, 13);
            this.label1.TabIndex = 7;
            this.label1.Text = "Answer Sheet";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(187, 13);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(87, 13);
            this.label2.TabIndex = 8;
            this.label2.Text = "Student Answers";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(333, 13);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(42, 13);
            this.label3.TabIndex = 9;
            this.label3.Text = "Results";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(568, 449);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lblResult);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.rtbGraded);
            this.Controls.Add(this.rtbStudentAnswers);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.rtbAnswers);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Driver’s License Exam";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.RichTextBox rtbAnswers;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.RichTextBox rtbStudentAnswers;
        private System.Windows.Forms.RichTextBox rtbGraded;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Label lblResult;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
    }
}

Answers.txt
1. B
2. D
3. A
4. A
5. C
6. A
7. B
8. A
9. C
10. D
11. B
12. C
13. D
14. A
15. D
16. C
17. C
18. B
19. D
20. A

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote