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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, luisanavarrogarcia
Which of the following statements correctly identifies a problem with sanitization methods? a. methods are not available to remove data ensuring that unauthorized personnel cannot retrieve data. b. even fully incinerated media can offer extractable data. c. personnel can perform sanitization steps improperly. d. stored data is physically etched into the media.
Answers: 1
image
Computers and Technology, 22.06.2019 10:00, banna01man
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
image
Computers and Technology, 22.06.2019 14:30, megkate
Complete the sentence based on your knowledge of the professional difficulties faced by music artists. digital technology allows audiences to see free live telecasts of music or dance performances through
Answers: 1
image
Computers and Technology, 22.06.2019 16:30, mesposito
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
You know the right answer?
C++
the history teacher at your school needs in grading a true/false test. the students' ids...

Questions in other subjects:

Konu
Social Studies, 03.09.2020 02:01