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: 90%–100%, A; 80%–89.99%, B; 70%–79.99%, C; 60%–69.99%, D; and 0%–59.99%, F.

Respuesta :

Answer:

see explaination

Explanation:

Program correct code

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string.h>

using namespace std;

int main()

{

ifstream infile("Chap8.txt");

if (!infile)

{

cout << "unable to open file so exiting from program :";

return 0;

}

char answers[25];

string str;

getline(infile, str);

for (int i = 0; i < str.length(); i++)

answers[i] = str[i];

while (!infile.eof()) {

getline(infile, str);

int i;

for (i = 0; i < str.length(); i++) {

if (str[i] == ' ')

break;

else

cout << str[i];

}

cout << " ";

int k = 0;

double score = 0;

for (int j = i + 1; j < str.length(); j++, k++) {

cout << str[j];

if (str[j] == ' ')

continue;

else if (str[j] == answers[k])

score = score + 2;

else if (str[j] != answers[k])

score = score - 1;

}

cout << " ";

double avg = 100.0 * score / 40.0;

//you were outputting the avg, you have to output score instead.

cout << score << " ";

//90%-100%, A; 80%-89.99%, B; 70%-79.99%, C; 60%-69.99%, D; and 0%-59.99%, F.

if (avg >= 90 && avg <= 100)

cout << "A" << endl;

else if (avg >= 80 && avg <= 89.99)

cout << "B" << endl;

else if (avg >= 70 && avg <= 79.99)

cout << "C" << endl;

else if (avg >= 60 && avg <= 69.99)

cout << "D" << endl;

else if (avg >= -15 && avg <= 59.99)

cout << "F" << endl;

}

return 0;

}

/*OUTPUT*/

LAU76359 TFTFTFTFTFTFTFTFTFTF 1 F

PUC98563 TFFTTTFTFTFFTTFFFTFF 34 B

RAM69522 TFFTTTFT FFTTFTTTFF 21 F

GPS22106 TFFTTTFTFTFTTTTTTTTT 28 C

UGP67851 FFFFFFFFFFFFFFFFFFFF 7 F

MUD02001 T F T F T F T F T F 17 F

IBM99887 FTTF FTTFFTFFFTT -3 F

CAM78999 FTFTFT TFTFTF FTFTFT 15 F

ACCESS MORE