StudentAnswers.txt A D B C B A C B D C A D B A C A D B C A A D B C A A D B D C A
ID: 3829183 • Letter: S
Question
StudentAnswers.txt
A
D
B
C
B
A
C
B
D
C
A
D
B
A
C
A
D
B
C
A
A
D
B
C
A
A
D
B
D
C
A
D
B
A
C
C
D
B
C
A
A
A
B
C
B
A
C
B
D
D
B
D
B
B
C
C
D
B
C
A
A
B
B
A
B
A
D
C
D
D
A
B
B
A
A
B
D
B
C
A
B
D
B
C
A
A
D
B
D
C
A
D
B
A
C
C
D
C
C
B
A
C
B
B
B
A
A
B
D
D
B
D
B
A
B
C
D
A
B
A
C
D
B
C
A
A
D
B
D
C
A
D
B
A
C
D
D
B
C
A
A
C
B
C
A
A
D
B
D
C
A
D
B
A
C
C
D
B
C
A
A
B
C
C
D
B
D
B
D
D
A
D
B
A
C
D
C
B
C
A
B
D
B
C
A
A
C
B
D
C
A
D
B
A
C
C
A
B
C
A
A
D
C
C
B
A
D
B
D
D
A
D
B
A
B
C
D
B
C
A
CorrectAnswers.txt
A
D
B
C
A
A
D
B
D
C
A
D
B
A
C
C
D
B
C
A
------------------------
please using c++ ( I need to cpp.file) visual studio 2015. please show me for code output and give to coments for coding and pseudo code for c++ thanks. please how to show your output.
please to code for this and output. thanks
10. Exam Grader One of your professors has asked you to write program to grade her final exa which consist of only 20 multi ple-choice questions. Each question has one of four pos A, B, C, or D. The file txt contains the correct answers all of the questions, with each answer written on a separate line. The first line contai the answer to the first question, the second li contains the answer to the second qu tion, and so forth. (Download the book's source code from the companion Web site www.pearsonhighered.com/gaddis. You will find the file in the Chapuca 07 folder. Write a program that reads the contents of the Correct Answers, txt e into a chi array, and then reads the contents of another file, containing a student's answers, in second char array. u can use the file StudentAnswers.txt for testing purpose is also in the Chapter 07 source code folder, available on the book's compani Web site.) The program should determine the number of questions that the stude missed, and then display the following: A list of the questions missed by the student, showing the correct answer and incorrect answer provided by the student for each missed question The total number of questions missed The percentage of questions answered correctly. This can be calculated as Correctly Answered Questions Total Number of Questions If the percentage of correct answered questions is 70% or greater, the p should indicate that the student passed the exam. Otherwise, it should that the student failed the exam, The correct Answers file contains exactly 20 answers that represent the correct answers for each question. That is, the first entry in the file is the correct answer for Problem l,the second entry is the correct answer for Problem 2, etc.) This file contains, in effect, the answer key for the exam, one answer per line. The studentAnswers file contains the answers the students actually entered on the exam, again, one answer per line. Each set of 20 lines in that file represents the answers for one student. We won't specify how many students are represented in the studentAnswers file (your program, therefore, needs to be able to detect this), but we will stipulate that there will not be any partial sets in that file. Your program should first read the answers in t into a character array. This array will serve as the answer key for the exam. Your program should then read the answers from the Student Answers file into another character array. You may safely use 300 as the size declarator for that array. Your program should then close both of the input files All subsequent processing will be done on the arrays only After all the input data have been read into the arrays, your program can begin to process the student answers array. (As we know, every set of 20 entries represents the answers for one student.) As your program examines the next answer, have it determine whether the answer was correct by comparing it against the proper entry in the answer key. Use accumulators to track the number of questions missed for each student so bullet points 2, 3, and 4 above can be answered correctly. Then print out your report for that student, reset the accumulators and counters, and proceed to the next student.Explanation / Answer
/*StudentExam.cpp*/
/*I Have Used the Same file For StudentAnswers and CorrectAnswers provided By you. place this file on the same folder you run the Program.*/
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
/*Variable Declaration*/
const int size=20;
static int count=0;
int i,j,k,limit,low=0,high=0,lowpercent=100,highpercent=0,no_of_student=0;/*all low and high are used for storing low percentage of student and
high percentage of a student.limit is used go to next 20answers*/
string correctAnswers[size];
string studentAnswers[1000];/*so that atleast 50 student record can be read*/
ifstream inFileC;
inFileC.open("CorrectAnswers.txt");/*storing answers in a string*/
if (inFileC)
{
for (i=0;i<20;i++)
{
inFileC>>correctAnswers[i];
}
}
else
{
cout<<"Unable to open "CorrectAnswers.txt""<<endl;
cout<<"Please check file location and try again."<<endl;
}
inFileC.close();
ifstream inFileS;
inFileS.open("StudentAnswers.txt");/*storing submitted answers of students*/
int t;
if (inFileS)
{
for (t=0;inFileS!='';t++)
{
inFileS>>studentAnswers[t];
}
}
else
{
cout<<"Unable to open "StudentAnswers.txt""<<endl;
cout<<"Please check file location and try again."<<endl;
}
inFileS.close();
no_of_student=t/20;/*finding number of student gave the Exam. and t is our input variable of studentanswer divided by 20.*/
i=0;
k=0;
limit=20;
while(i<no_of_student)
{
cout<<" Report for Student "<<i+1<<": -----------------------";/*i+1 here because i is starting from 0*/
for (j=0;k<limit;k++,j++)/*for first time limit is equal to 20 which is increased later*/
{
if (correctAnswers[j]!=studentAnswers[k])
{
count++;
}
}
int percent=((double)(20-count)/20)*100;
cout<<" Missed "<<count<<" out of 20 questions for "<<percent<<" % Correct.";
cout<<" Questions Missed: ";
k=k-20;/*so that it come again to the same point where it started*/
count=0;
for (j=0;k<limit;k++,j++)
{
if (correctAnswers[j]!=studentAnswers[k])
{
cout<<" "<<k%20+1<<"["<<correctAnswers[j]<<","<<studentAnswers[k]<<"]";
count++;
}
}
count=0;
if (percent>=70)
{
cout<<" This Student Pass The Exam!";
if(highpercent<percent)
{
highpercent=percent;
high=i+1;
}
}
else
{
cout<<" This Student Failed The Exams.";
if(lowpercent>percent)
{
lowpercent=percent;
low=i+1;
}
}
i++;/*increment the Counter.*/
limit=limit+20;
}/*End of While Loop*/
cout<<" Student "<<high<<" had the best grade with "<<highpercent<<" %.";
cout<<" Student "<<low<<" had the worst grade with "<<lowpercent<<" %.";
return 0;
}
/******************OUTPUT****************************
Report for Student 1:
-----------------------
Missed 3 out of 20 questions for 85 % Correct.
Questions Missed:
5[A,B] 7[D,C] 16[C,A]
This Student Pass The Exam!
Report for Student 2:
-----------------------
Missed 0 out of 20 questions for 100 % Correct.
Questions Missed:
This Student Pass The Exam!
Report for Student 3:
-----------------------
Missed 6 out of 20 questions for 70 % Correct.
Questions Missed:
2[D,A] 5[A,B] 7[D,C] 10[C,D] 11[A,B] 14[A,B]
This Student Pass The Exam!
Report for Student 4:
-----------------------
Missed 8 out of 20 questions for 60 % Correct.
Questions Missed:
2[D,B] 4[C,A] 5[A,B] 8[B,C] 10[C,D] 12[D,B] 15[C,A] 16[C,B]
This Student Failed The Exams.
Report for Student 5:
-----------------------
Missed 3 out of 20 questions for 85 % Correct.
Questions Missed:
1[A,B] 18[B,C] 20[A,B]
This Student Pass The Exam!
Report for Student 6:
-----------------------
Missed 9 out of 20 questions for 55 % Correct.
Questions Missed:
2[D,C] 4[C,B] 5[A,B] 7[D,A] 10[C,D] 11[A,B] 15[C,B] 18[B,A] 19[C,B]
This Student Failed The Exams.
Report for Student 7:
-----------------------
Missed 2 out of 20 questions for 90 % Correct.
Questions Missed:
1[A,C] 16[C,D]
This Student Pass The Exam!
Report for Student 8:
-----------------------
Missed 1 out of 20 questions for 95 % Correct.
Questions Missed:
2[D,C]
This Student Pass The Exam!
Report for Student 9:
-----------------------
Missed 7 out of 20 questions for 65 % Correct.
Questions Missed:
2[D,B] 3[B,C] 5[A,D] 6[A,B] 10[C,D] 16[C,D] 17[D,C]
This Student Failed The Exams.
Report for Student 10:
-----------------------
Missed 3 out of 20 questions for 85 % Correct.
Questions Missed:
1[A,B] 7[D,C] 17[D,A]
This Student Pass The Exam!
Report for Student 11:
-----------------------
Missed 4 out of 20 questions for 80 % Correct.
Questions Missed:
3[B,C] 5[A,B] 10[C,D] 15[C,B]
This Student Pass The Exam!
Student 2 had the best grade with 100 %.
Student 6 had the worst grade with 55 %.
--------------------------------
Process exited after 0.1116 seconds with return value 0
Press any key to continue . . .
****************************************************/