/*
This program will take a file
with the answers to a test
and compare them to the
answers a student got in
another file.
*/
#include <iostream>
#include <fstream>
using namespace std;
const int SIZE = 20; //global constant
int calcMissed() //gets files to find student's incorrect answers
{
ifstream answers; //correct answers stored in this variable
answers.open(correctanswers.txt);
char cAnswers[SIZE] = {answers}; //stored into array for calculation
ifstream student; //student answers stored in this variable
student.open(studentanswers.txt);
char sAnswers[SIZE] = student;
int incorrect = 0;
for(int i = 0; i < 20; i++)
{
if(sAnswers[i] != cAnswers[i])
{
incorrect += 1;
}
}
answers.close();
student.close();
return incorrect;
}
int calcCorrect(); //gets files to find student's correct answers
{
ifstream answers; //correct answers stored in this variable
answers.open(correctanswers.txt);
char cAnswers[SIZE] = answers; //stored into array for calculation
ifstream student; //student answers stored in this variable
student.open(studentanswers.txt);
char sAnswers[SIZE] = student;
int correct = 0;
for(int i = 0; i < 20; i++)
{
if(sAnswers[i] == cAnswers[i])
{
correct += 1;
}
}
answers.close();
student.close();
return correct;
}
int main()
{
ifstream answers; //correct answers stored in this variable
answers.open(correctanswers.txt);
char cAnswers[SIZE] = answers; //stored into array for calculation
ifstream student; //student answers stored in this variable
student.open(studentanswers.txt);
char sAnswers[SIZE] = student;
int correct[SIZE] = calcCorrect();
int incorrect[SIZE] = calcMissed();
cout << "The student got " << correct << " of the answers correct." << endl;
cout << "The student got " << incorrect << " of the answers incorrect." << endl;
cout << "#" << "\t" << "Correct Answer" << "\t" << "Student's Answer" << endl;
for(int i = 0; i < SIZE; i++)
{
cout << (i + 1) << "\t" << correct[i] << "\t" << incorrect[i] << endl;
}
return 0;
}