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 10:50
A911 dispatcher is the sole sender of messages to all police officers. while on patrol, officers communicate with the dispatcher who, in turn, relays messages to other officers. the officers do not communicate directly with one another. this illustrates a network.
Answers: 1
question
Computers and Technology, 22.06.2019 11:50
You have written, as part of a school assignment, a research paper on the solar system. you want to share this paper on your school website. on which type of server will you upload it?
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
What allows you to create a wireless connection among your smart devices
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
Jennifer has to set up a network in a factory with an environment that has a lot of electrical interference. which cable would she prefer to use? jennifer would prefer to use because its metal sheath reduces interference.
Answers: 1
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, 13.04.2021 23:10
question
English, 13.04.2021 23:10
question
Mathematics, 13.04.2021 23:10
question
Chemistry, 13.04.2021 23:10
question
Mathematics, 13.04.2021 23:10
question
Biology, 13.04.2021 23:10
question
Health, 13.04.2021 23:10
Questions on the website: 13722363