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

The history teacher at your school needs help in grading a True/False test. The

ID: 3722138 • Letter: T

Question

The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form:

TFFTFFTTTTFFTFTFTFTT

Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry:

ABC54301 TFTFTFTT TFTFTFFTTFT

indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9. The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data.

The output should be the student’s ID, followed by the answers, followed by the test score, followed by the test grade. Assume the following grade scale:

Percentage Letter Grade 90%-100% A 80%– 89.99% B 70%–79.99% C 60%–69.99% D 0%–59.99% F

Explanation / Answer

#include<iostream>
#include<fstream>
#include <string>

#define M 4 //maximum number of students

using namespace std;
int main()
{
string *studentID; // array of pointers to c-strings
string *studentResult; // array of pointers to c-strings
string temp; //temporary variable
string Result; //string to hold correct result
int index;
double score=0.0;
double scale=0.0;
char grade;
int N=0; //maximum number of questions
cout<<"Enter number of exam questions: ";
cin>>N;
ifstream fin;
fin.open("input.txt");
int i=0;
getline(fin,Result); //store first line of file in Result
studentID=new string[M+1]; //allocate memory to studentID
studentResult=new string[M+1]; //allocate memory to studentResult

for(i=0;i<M;i++)
{
getline(fin,temp);
index=temp.find(' ');
studentID[i]=temp.substr(0,index);
studentResult[i]=temp.substr(index+1);
}
fin.close(); //close file
cout<<endl<<"Processing Data";
cout<<endl<<"Key : "<<Result<<endl;

//calculate scores fo students
for(i=0;i<M;i++)
{
score=0.0; //initialize score to 0
cout<<endl<<studentID[i];
cout<<" "<<studentResult[i];
for(int j=0;j<N;j++)
{
if(studentResult[i][j]==NULL || studentResult[i][j]==' ')
{
studentResult[i][j]='';
break;
}
if(Result[j]==studentResult[i][j]) //if correct result
score=score+2; //add 2 to score
else if(studentResult[i][j]==' ' || studentResult[i][j]==' ') //if result is blank
score=score+0; //add zero to score
else
score=score-1; //deduct 1 from score
}

cout<<" "<<score;
scale=(score/40)*100; //calculate scale
//calculate grades
if(scale>=90 && scale<=100) grade='A'; //90%-100%, A;
else if(scale>=80 && scale<90) grade='B'; //80%-89.99%, B;
else if(scale>=70 && scale<80) grade='C'; //70%-79.99%, C;
else if(scale>=60 && scale<70) grade='D'; //60%-69.99%, D;
else if(scale>=0 && scale<60) grade='F'; //0-59.99%, F.

cout<<" "<<grade;
}
cout<<endl;
system("pause");
return 0;
}