Question

In: Computer Science

A multiple-choice examination consists of 20 questions. Each question has five choices, labeled A, B, C,...

A multiple-choice examination consists of 20 questions. Each question has five choices, labeled A, B, C, D and E. All data for that exam is stored in a file exam.txt. The first line of data contains the correct answers to the twenty questions in the first 20 consecutive (one after the other) character positions.
For Example: BECDCBAADEBACBEDDBED

Each subsequent line in the file contains the answers for a single candidate. Data on a line consists of a candidate number (an integer), then by one or more spaces, followed by the twenty answers given by the candidate in the next 20 consecutive character positions. An X is used if a candidate did not answer a particular question. A sample line is as follows:

5555 BECDCXACCAEDCBEDDACB

There can be an unlimited number of candidates. A line containing a “candidate number” 0 indicates the end of the data.

A student’s final score is calculated by adding up the points awarded for all the questions. Points for a question are awarded as follows:
• Correct answer 4 points
• Wrong answer -1 point
• No answer 0 points

Write a C# program to process the data in the file exam.txt and generate a report that shows:
1. Each candidate number and their final score (the total points obtained by the candidate).
2. The total number of candidates.
3. The number of correct responses to each of the 20 questions.
4. The minimum score attained by a student in the exam.
5. The maximum score attained by a student in the exam.
6. The average score attained by a student in the exam.

The report must be written to a file called Report.txt.

Solutions

Expert Solution

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace smallcsarp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the file name : ");

// enter file name
String fileName = Console.ReadLine();

// raed alla line in a string
string[] lines = File.ReadAllLines(fileName);

// store all correct answers
char[] correctAnswers = lines[0].ToCharArray();

// to collect correct answers
int[] noOfcorrectAns = new int[20];

// minimum and maximum value
int max = 0, min = 100;

// student number
int[] stdNos = new int[lines.Length-1];

// number of student answers
int[] stdAns = new int[lines.Length - 1];

// each student score
int[] stdScore = new int[lines.Length - 1];

// initialize number of answers
for (int i = 0; i < 20; i++)
{
noOfcorrectAns[i] = 0;
}


for(int i = 1; i < lines.Length - 1; i++)
{
// split line
String[] spltRslt = lines[i].Split(' ');

// set student number
stdNos[i - 1] = Convert.ToInt16(spltRslt[0]);

// student answer
char[] studentAns = spltRslt[1].ToCharArray();

stdAns[i] = 0;
int total = 0;

for (int j = 0; j < 20; j++)
{
// for correct answer   
if (correctAnswers[j] == studentAns[j])
{
// total added by 4
total += 4;

// correct answers
noOfcorrectAns[j]++;
}
else
{
if (correctAnswers[j] == 'X')
{
total += 0;
}

// wrong answer
else
{
total -= 1;
}
}
}

// set score
stdScore[i] = total;

// obtain minimum value
if (min > total)
{
min = total;
}

// obtain maximum value
if (max < total)
{
max = total;
}
}


// write in a file
Console.Write("Enter file name to write : ");
String writeFile = Console.ReadLine();

StreamWriter writer = new StreamWriter(writeFile);

// display report

Console.WriteLine("Candidate Number and their Score");
writer.WriteLine("Candidate Number and their Score");

for(int i = 0; i < lines.Length-2; i++)
{
Console.WriteLine("{0} {1}",stdNos[i],stdScore[i]);
writer.WriteLine("{0} {1}", stdNos[i], stdScore[i]);
}

Console.WriteLine("Total number of candidate is {0}",lines.Length-2);
writer.WriteLine("Total number of candidate is {0}", lines.Length - 2);
Console.WriteLine("Numer of correct response : ");
writer.WriteLine("Numer of correct response : ");
for (int i = 0; i < 20; i++)
{
Console.WriteLine("Question {0} is {1}", i+1,noOfcorrectAns[i] );
writer.WriteLine("Question {0} is {1}", i + 1, noOfcorrectAns[i]);
}
Console.WriteLine("Maximum score by a student in exam : {0}",max);
writer.WriteLine("Maximum score by a student in exam : {0}", max);
Console.WriteLine("Minimum score by a student in exam : {0}",min);
writer.WriteLine("Minimum score by a student in exam : {0}", min);

double stotal = 0;
for (int i = 0; i < lines.Length - 2; i++)
{
stotal += stdScore[i];
}

double avg = stotal / (double)(lines.Length - 2);

Console.WriteLine("Average score by studenin the exam : {0}",avg);
writer.WriteLine("Average score by studenin the exam : {0}", avg);

writer.Close();

Console.ReadKey();
}
}
}

BECDCBAADEBACBEDDBED
2342 ABBXABBDAEFFAEFDEACA
4323 XAXACCAXADAEXACEAXBC
5673 ADEXDAECXABAXACDEACA
4525 CADXECBACCACAXXEDACX
2345 DECBCAXEDCAXAXDBXCDX
6745 XADECABXCADECXBBXCAD
3455 EXXEDXACDDAEDCBEDACD
6574 ECDBBDBABBBEDDXDAEDB
2342 AADEBBBAFAEDABEEDXXA
6464 DAEXABADEXADEDACAEXE
3452 AAABXXAEXACDDACDEAXA
7465 CDAABCXEADCAXDAECBXC
6456 CADEADADABACACAXEDAX
5345 CAEEBCACDEABADEACDEA
1232 XEDACEDDDEADCCBACCDA
7567 ADADBBACADECADAECDEA
4353 BCADXEDACABBCAXDEABX
6456 AEAXAXDEABDAEXDEABXX
0


Related Solutions

A multiple-choice examination consists of 85 questions, each having possible choices a, b, c, d, and...
A multiple-choice examination consists of 85 questions, each having possible choices a, b, c, d, and e. Approximate the probability that a student will get at most 18 answers correct if she randomly guesses at each answer. (Note that, if she randomly guesses at each answer, then the probability that she gets any one answer correct is 0.2.) Use the normal approximation to the binomial with a correction for continuity.
A quiz consists of 20 multiple choice​ questions, each with five possible​ answers, only one of...
A quiz consists of 20 multiple choice​ questions, each with five possible​ answers, only one of which is correct. If a student guesses on each​ question, what is the mean and standard deviation of the number of correct​ answers? Round to the nearest thousandth. ______________________________________________________________ A. The mean is 10. The standard deviation is 3.162. B.The mean is 4. The standard deviation is 1.789. C.The mean is 10. The standard deviation is 1.789. D.The mean is 4. The standard deviation...
A student is given 20 multiple choice questions. Each multiple choice question has 4 options &...
A student is given 20 multiple choice questions. Each multiple choice question has 4 options & only one correct answer. The student answers all the questions in a random manner. a) What is the probability the student scores 80% or above? b) What is the probability the student scores 50% or above?
Problem 3.An exam has 30 multiple choice questions. Each question has five answer choices, ofwhich exactly...
Problem 3.An exam has 30 multiple choice questions. Each question has five answer choices, ofwhich exactly one is correct. In how many different ways can a student who answers all questionsget at least 27 of them correct?
Consider a multiple-choice examination with 50 questions. Each question has four possible answers.
Consider a multiple-choice examination with 50 questions. Each question has four possible answers. Assume that a student who has done the homework and attended lectures has a 65% chance of answering any question correctly. (Round your answers to two decimal places.) (a) A student must answer 43 or more questions correctly to obtain a grade of A. What percentage of the students who have done their homework and attended lectures will obtain a grade of A on this multiple-choice examination?...
In a multiple choice exam, there are 7 questions and 4 choices for each question (a,...
In a multiple choice exam, there are 7 questions and 4 choices for each question (a, b, c, d). Nancy has not studied for the exam at all and decides to randomly guess the answers. What is the probability that: (please round all answers to four decimal places) a) the first question she gets right is question number 3? b) she gets all of the questions right? c) she gets at least one question right?
A standardized test consists of 100 multiple-choice questions. Each question has five possible answers, only one...
A standardized test consists of 100 multiple-choice questions. Each question has five possible answers, only one of which is correct. Four points are awarded for each correct answer. To discourage guessing, one point is taken away for every answer that is not correct (this includes answers that are missing). The company that creates the test has to understand how well a student could do just by random guessing. Suppose a student answers each question by picking one of the five...
A multiple-choice test has 6 questions. There are 4 choices for each question. A student who...
A multiple-choice test has 6 questions. There are 4 choices for each question. A student who has not studied for the test decides to answer all questions randomly with a Probability of success = p =.25. Let X represent the number of correct answers out of six questions. (i) Use binomial distribution to complete the table (ii) Find the probability that the student will be successful in at least 4 questions. (iii) Find the probability that the student will be...
Consider a multiple-choice examination with 50 questions. Each question has four possible answers. Assume that a...
Consider a multiple-choice examination with 50 questions. Each question has four possible answers. Assume that a student who has done the homework and attended lectures has a 65% chance of answering any question correctly. (Round your answers to two decimal places.) (a)A student must answer 44 or more questions correctly to obtain a grade of A. What percentage of the students who have done their homework and attended lectures will obtain a grade of A on this multiple-choice examination? Use...
Consider a multiple-choice examination with 50 questions. Each question has four possible answers. Assume that a...
Consider a multiple-choice examination with 50 questions. Each question has four possible answers. Assume that a student who has done the homework and attended lectures has a 75% probability of answering any question correctly. A student must answer 43 or more questions correctly to obtain a grade of A. What percentage of the students who have done their homework and attended lectures will obtain a grade of A on this multiple-choice examination? A student who answers 35 to 39 questions...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT