The History teacher needs help in grading a true/false test. The students' ID's and test answers are stored in a file (dont worry about the file). The first entry in the file contains answers to the test in this form.
T F F T F F T T T T F F T F T F T F T F
Every other entry in the file is the students ID, followed by a blank, followed by the students responses.
For example, the entry
ABC54301 T F T F T F T T T F T F T F F T T F T
indicates that the students ID is ABC54301 and the answer to question 1 is true, the question for number is false, and so on. The student did not answer question 9. The exam has 20 questions. Each correct answer is awarded two points, each wrong answer gets -1 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, and 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, 50.99 -0 F. Finally show the number of students who took this test.
Requirements:
The program should be written for any number of student results, not just 8.
You must have the following functions:
getAnswers – passes the input file stream and an array to store the students answers. Reads in the students answers
getKey – passes the input file stream and an array to hold the answer key. Reads in the answer Key for the test
calcScore – passes the arrays with the answer key and the students answers. Calculates the students score and the letter grade, and prints out the information
Okay I understand functions a lot better. Maybe that isn't my problem here? I'm getting different results when I try and output "what the input stream read from the file"
// functions for students answers, answer key and calculating students scores
void getAnswers(ifstream& input, char studentAns[]) // pass stream and array varaibles
{ //
int i; //
for (i = 0; i < SIZE; i++)
{
input.get(studentAns[i]);
}
//
}
void getKey(ifstream& input, char ansKey[]) //
{ //
int i; //
for (i = 0; i < SIZE; i++)
{
input.get(ansKey[i]);
}
//
}
void calcScore(char ak[], char sa[], int score)
{
int i;
char aSpace = ' ';
for (i = 0; i < SIZE; i++)
{
if ( ak[i] == sa[i])
score = score + 2;
else if (ak[i] != sa[i])
score = score - 1;
else if (aSpace)
score = score + 0;
}
if (score >= 90 && score <= 100)
cout << score << setw(2) << "A" << endl;