subject

C++
the history teacher at your school needs 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:
tffttftftftt
every other entry in the file is the student id, followed by a blank, followed by the student's responses. for example, the
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; 0%-59.99%, f.
the input is
tfftttftftffttftttff
lau76359 tftftftftftftftftftf
puc98563 tfftttftftffttffftff
ram69522 tfftttft ffttftttff
gps22106 tfftttftftf
ugp67851
mud02001 t f t f t f t f t f
ibm99887 fttf fttfftffftt
cam78999 ftftft tftftf ftftft
my code is this:
#include
#include
#include
#include
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. {
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;
cout < < avg < < " ";
//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;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:00
Eva has many contacts on the professional networking site she uses which contacts are considered second degree
Answers: 3
question
Computers and Technology, 23.06.2019 15:20
What does a bonus object do? a. subtracts lives b. keeps track of a player's health c. gives a player an advantage d. makes text appear
Answers: 1
question
Computers and Technology, 24.06.2019 17:00
Aman travel 200m towards east< br /> from his house then takes left< br /> to turn and moves 200 m north< br /> find the displacement & distance.< br />
Answers: 3
question
Computers and Technology, 24.06.2019 17:30
What is the next step if your volume does not work on computer
Answers: 2
You know the right answer?
C++
the history teacher at your school needs in grading a true/false test. the students' ids...
Questions
question
Mathematics, 22.07.2021 05:00
question
Mathematics, 22.07.2021 05:00
question
Business, 22.07.2021 05:00
question
Health, 22.07.2021 05:00
question
Chemistry, 22.07.2021 05:00
Questions on the website: 13722363