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
|
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
// prototypes
void getgrad (double[], double [], float &);
bool readarr (double[], ifstream &);
bool readInStudentAnswer(ifstream &, string &, double[]);
int main()
{
//declaring variables
ifstream inFile;
ofstream outFile;
string StudentID;
double answer[20];
double STUDENTANSWERS[20];
float Scores;
//opening files
inFile.open("Answers.txt");
outFile.open("StudentsScores.txt");
//function call for reading in answer key
readarr(answer, inFile);
// while loop that reads in student ID and calls getgrad function and outputs it into output file
while (readInStudentAnswer(inFile, StudentID, STUDENTANSWERS))
{
getgrad(answer, STUDENTANSWERS, Scores);
cout << StudentID << Scores << endl;
outFile << StudentID << Scores;
}
return 0;
}
// function to read in the answer key
bool readarr(double A[], ifstream & b)
{
int i;
for (i = 0; i <= 20; i++)
{
b >> A[i];
}
return bool(b);
}
//function to read in the student answer
bool readInStudentAnswer(ifstream & c, string & studID, double studANS[])
{
c >> studID;
for (int i = 0; i <= 20; i++)
{
c >> studANS[i];
}
return bool(c);
}
// function to compare student grade to the answer key and get their scores
void getgrad(double B[], double studANS[], float & grade)
{
float GRADES = 0;
int i;
for (i = 0; i < 20; i++)
{
if (B[i] == studANS[i])
{
GRADES++;
}
}
grade = GRADES += 5;
}
|