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