I have a file with the first entry as TFFTFFTTTTFFTFTFTFTT. Every other entry in
ID: 3623370 • Letter: I
Question
I have a file with the first entry as TFFTFFTTTTFFTFTFTFTT. Every other entry in the file is the student ID, followed by a blank, followed by the student's responses. Ex:ABC54301 TFTFTFTT TFTFTFFTTFT
The exam has 20 questions and the class has 20 students. Each correct answer is awarded 2 points, each wrong answer gets 1 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. This is the following grade scale: 90-100 = A, 80-89.99 = B, 70-79.99 = C, 60-69.99 = D, and 0-59.99 = F. PLEASE INCLUDE ERROR CHECKING!!!
Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
#include <cstring>
#include<iomanip>
using namespace std;
char letter(int);
int main()
{string key,answer,id;
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;
}
in>>key;
in>>id;
while(in)
{in.get(space);
for(i=0;i<20;i++)
answer[i]=' ';
getline(in,answer);
score = 0;
for(i=0;i<20; i++)
{if(answer[i]==' ')
score+=0;
else if(answer[i]==key[i])
score+=2;
else
score--;
}
cout<<id<<" "<<setw(21)<<left<<answer<<" "<<score<<" "<<letter((int)((double)score/40.*10.))<<endl;
in>>id;
}
in.close();
system("pause");
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
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.