Write a program called Grader_LastNameFirstName.cpp that processes the True/Fals
ID: 3604301 • Letter: W
Question
Write a program called Grader_LastNameFirstName.cpp that processes the True/False data from a file called “testinformation.txt”.
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 e x a m has 20 questions, and the class could have up to 150 students. This class only had 4 students. Each student has a different student ID and no student ID can appear more than one time. “Hint Hint” If it appears more than once; only takes the first entry.
Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points.
The output should be the student’s ID, followed by the answers, followed by the test score, followed by the test grade as show below:
Assume the following grade scale:
90%–100%, A;
80%–89.99%, B;
70%–79.99%, C;
60%–69.99%, D;
0%–59.99%, F.
Write the output to the screen and output the results for the class to a text file called Grades_lastnamefirstname.txt. Also output each of the students results in a separate file with their student ID and your lastnameFirstname.txt For example, for the above output, your program would have 5 output files.
Grades_lastnamefirstname.txt (contains everyone grades) as Grades_RogersGregory.txt
ABC54102_lastnamefirstname.txt as ABC54102_RogersGregory.txt
DEF56278_lastnamefirstname.txt as DEF56278_RogersGregory.txt
ABC42366_lastnamefirstname.txt as ABC42366_RogersGregory.txt
ABC42586_lastnamefirstname.txt as ABC42586_RogersGregory.txt
Processing Data Key TTFTFTTTFTFTFFTTFTTF ABC54102 T FTFTFTTTFTTFTTF TF 27 D DEF56278 TTFTFTTTFTFTFFTTFTTF 40 A ABC42366 TTFTFTTTFTFTFFTTF ABC42586 TTTTFTTTTFTFFFTF 34 B 26 DExplanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
char letter(int);
int main()
{char key[21],answer[21],id[9];
int score,i;
char space;
ifstream in;
in.open("input.txt"); //open file
if(in.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
ofstream outFile;
outFile.open("Output.txt");
in.get(key, 21);
in>>id;
while(in)
{in.get(space);
for(i=0;i<20;i++)
answer[i]=' ';
answer[20]='';
in.get(answer,21);
score = 0;
for(i=0;i<20; i++)
{if(answer[i]==' ')
score+=0;
else if(answer[i]==key[i])
score+=2;
else
score--;
}
outFile<<id<<" "<<setw(21)<<left<<answer<<" "<<score<<" "<<letter((int)((double)score/40.*10.))<<endl;
in>>id;
}
in.close();
outFile.close();
return 0;
}
char letter(int score)
{switch(score)
{case 10:
case 9: return 'A';
case 8: return 'B';
case 7: return 'C';
case 6: return 'D';
default: return 'F';
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.