1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main ()
{
char answers[21];
char studentAnswers[21];
string studentID;
int correct = 0;
float grade = 0.0;
float totalGrade = 40.0;
char finalGrade;
ifstream inFile;
inFile.open("input.txt");
inFile.get(answers,21);
while (inFile >> studentID)
{
cout << "Student ID: " << studentID << endl;
for(int x=0; x<21; x++)
{
inFile.get(studentAnswers[x]);
}
for(int z=0; z<20; z++)
{
if(answers[z] == studentAnswers[z+1])
{
correct += 2;
}
if(answers[z] != studentAnswers[z+1])
{
correct -=1;
}
}
cout << "Student's Answers:";
for(int g=0; g<20; g++)
{
cout << studentAnswers[g+1];
}
cout << endl << "Test Score: " << correct << endl;
grade = (correct / totalGrade) * 100;
if (grade >= 90)
{
finalGrade = 'A';
}
else if (grade >= 80)
{
finalGrade = 'B';
}
else if (grade >= 70)
{
finalGrade = 'C';
}
else if (grade >= 60)
{
finalGrade = 'D';
}
else
{
finalGrade = 'F';
}
cout << "Test Grade: " << finalGrade << endl << endl;
correct = 0;
grade = 0.0;
studentID.clear();
}
inFile.close();
return 0;
}
|
OUTPUT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
Student ID: ABC54102
Student's Answers:T FTFTFTTTFTTFTTF TF
Test Score: 25
Test Grade: D
Student ID: DEF56278
Student's Answers:TTFTFTTTFTFTFFTTFTTF
Test Score: 40
Test Grade: A
Student ID: ABC42366
Student's Answers:TTFTFTTTFTFTFFTTF
AB
Test Score: 31
Test Grade: C
Student ID: C42586
Student's Answers:TTTTFTTT TFTFFFTF
LK
Test Score: 22
Test Grade: F
Student ID: J81672
Student's Answers: TTTFTFFTFFTTFTFTF
Test Score: 4
Test Grade: F
Student ID: STD24151
Student's Answers: TFTFTTTFTFTFFTTFFTF
Test Score: 34
Test Grade: B
|
Input from text file
1 2 3 4 5 6 7
|
TTFTFTTTFTFTFFTTFTTF
ABC54102 T FTFTFTTTFTTFTTF TF
DEF56278 TTFTFTTTFTFTFFTTFTTF
ABC42366 TTFTFTTTFTFTFFTTF
ABC42586 TTTTFTTT TFTFFFTF
LKJ81672 TTTFTFFTFFTTFTFTF
STD24151 TFTFTTTFTFTFFTTF
|
Assignment:
The Computer Science department 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 the answers to the test in the form:
TFFTFFTTTTTTFFTFTFTT
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 -1 point and no answer gets 0 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.
________________________________________________________________________________
The problem in the output is where the student ID should be 8 characters long two of them are being cut off and are placed in the wrong location. I'm guessing it's because the array, but I'm not sure how to fix it.